Skip to contents

Build a YAML file (.gihub/workflows/memoir.yml) to knit the documents of the project to GitHub Pages. The workflow knits all R Markdown files according their header: all output formats are produced and stored into the gh-pages branch of the project.

Usage

build_ghworkflow()

Value

The content of the YAML file as a vector of characters, invisibly. Each element is a line of the file.

Details

All HTML outputs have the same name so the last one knitted overwrites the previous ones. Keep only one HTML format in the header of each RMarkdown file.

No DESCRIPTION file is necessary in the project to install packages. They must be declared in the options code chunk of each .Rmd file (index.Rmd for the memoir template).

Two secrets must have been stored in the GitHub account:

  • GH_PAT: a valid access token,

  • EMAIL: the email address to send the workflow results to.

Examples

## Simulate the creation of a new project
# Save working directory
original_wd <- getwd()
# Get a temporary working directory
wd <- tempfile("example")
# Simulate File > New File > R Markdown... > From Template > Simple Article
rmarkdown::draft(wd, template="simple_article", package="memoiR", edit=FALSE)
# Go to temp directory
setwd(wd)
# Make it the current project
usethis::proj_set(path = ".", force = TRUE)
#>  Setting active project to
#>   "/private/var/folders/t_/mmhnh941511_hp2lwh383bp00000gn/T/Rtmp4sA4mI/example232432115b42".

# Build GitHub Actions Workflow script
build_ghworkflow()
#>  Writing .github/workflows/memoir.yml.
# Content
readLines(".github/workflows/memoir.yml")
#>  [1] "on:"                                                                                               
#>  [2] "  push:"                                                                                           
#>  [3] "   branches:"                                                                                      
#>  [4] "     - master"                                                                                     
#>  [5] ""                                                                                                  
#>  [6] "name: rmarkdown"                                                                                   
#>  [7] ""                                                                                                  
#>  [8] "jobs:"                                                                                             
#>  [9] "  render:"                                                                                         
#> [10] "    runs-on: macOS-latest"                                                                         
#> [11] "    steps:"                                                                                        
#> [12] "      - name: Checkout repo"                                                                       
#> [13] "        uses: actions/checkout@v4"                                                                 
#> [14] "      - name: Setup R"                                                                             
#> [15] "        uses: r-lib/actions/setup-r@v2"                                                            
#> [16] "      - name: Install pandoc"                                                                      
#> [17] "        uses: r-lib/actions/setup-pandoc@v2"                                                       
#> [18] "      - name: Install dependencies"                                                                
#> [19] "        env:"                                                                                      
#> [20] "          GITHUB_PAT: ${{ secrets.GH_PAT }}"                                                       
#> [21] "        run: |"                                                                                    
#> [22] "          options(pkgType = \"binary\")"                                                           
#> [23] "          options(install.packages.check.source = \"no\")"                                         
#> [24] "          install.packages(c(\"distill\", \"downlit\", \"memoiR\", \"rmdformats\", \"tinytex\"))"  
#> [25] "          tinytex::install_tinytex(bundle = \"TinyTeX\")"                                          
#> [26] "          tinytex::tlmgr_install(\"hyphen-french\")"                                               
#> [27] "          tinytex::tlmgr_install(\"hyphen-italian\")"                                              
#> [28] "        shell: Rscript {0}"                                                                        
#> [29] "      - name: Render Rmarkdown files"                                                              
#> [30] "        env:"                                                                                      
#> [31] "          GITHUB_PAT: ${{ secrets.GH_PAT }}"                                                       
#> [32] "        run: |"                                                                                    
#> [33] "          Sys.setlocale(\"LC_TIME\", \"en_US\")"                                                   
#> [34] "          lapply(list.files(pattern = \"*.Rmd\"), function(file) rmarkdown::render(file, \"all\"))"
#> [35] "          memoiR::build_githubpages()"                                                             
#> [36] "        shell: Rscript {0}"                                                                        
#> [37] "      - name: Upload artifact"                                                                     
#> [38] "        uses: actions/upload-artifact@v4"                                                          
#> [39] "        with:"                                                                                     
#> [40] "          name: ghpages"                                                                           
#> [41] "          path: docs"                                                                              
#> [42] "  checkout-and-deploy:"                                                                            
#> [43] "    runs-on: ubuntu-latest"                                                                        
#> [44] "    needs: render"                                                                                 
#> [45] "    permissions:"                                                                                  
#> [46] "      contents: write"                                                                             
#> [47] "    steps:"                                                                                        
#> [48] "      - name: Download artifact"                                                                   
#> [49] "        uses: actions/download-artifact@v4"                                                        
#> [50] "        with:"                                                                                     
#> [51] "          name: ghpages"                                                                           
#> [52] "          path: docs"                                                                              
#> [53] "      - name: Deploy to GitHub Pages"                                                              
#> [54] "        uses: Cecilapp/GitHub-Pages-deploy@v3"                                                     
#> [55] "        env:"                                                                                      
#> [56] "          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}"                                               
#> [57] "        with:"                                                                                     
#> [58] "          email: ${{ secrets.EMAIL }}"                                                             
#> [59] "          build_dir: docs"                                                                         
#> [60] "          jekyll: yes"                                                                             

## End of the example: cleanup
# Return to the original working directory and clean up
setwd(original_wd)
unlink(wd, recursive = TRUE)