# Generate some sample data
<- 1:10
x <- x^2
y
# Create a basic scatter plot
plot(x, y, type = "b", col = "blue",
main = "Base R Plot",
xlab = "X values", ylab = "Y = X squared")
Adding Exectutable Code
You can add executable code chunks to your pages. See quarto Using R documentation for more information.
Example Code Chunk
Adding Packages & Common Errors
If you are working on some code that has additional package dependencies, you may need to add them to your GitHub Actions workflow so those code chunks can be rendered and executed properly.
This template includes a basic render-and-publish.yml
workflow that should work for most applications.
Package Errors
If you are encountering errors in your GitHub actions which are not allowing you to publish your pages, you will need to change your workflow.
On your GitHub repository, click on the ‘Actions’ tab and look for failed workflows. You can click on the failed workflow to identify where the action failed. Below is an example fail-point where a required package cannot be found
Edit Basic Workflow
One solution to this error is to include your additional packages in the basic render-and-publish.yml
workflow.
Open your
render-and-publish.yml
workflow fileIdentify the following lines (should be around line 17 & 18)
- name: Install packages (needed for Rmd) run: Rscript -e 'install.packages(c("rmarkdown", "knitr", "jsonlite"))'
Add packages to the list on the second line
Example:
run: Rscript -e 'install.packages(c("rmarkdown", "knitr", "jsonlite", "dplyr"))'
Commit the changes and your workflow should re-run without errors
Using renv Workflow
If you are still encountering package errors you may need to set up a renv
workflow in your R project. This will manage the package dependencies and ensure the proper packages are installed and loaded for rendered GitHub pages.
- Make sure you have an R project open for your repository and initialize
renv
in the project by running the following coderenv::init()
(you may need to install therenv
package). This will create a localerenv
folder and arenv.lock
file with the packages you loaded - Install and load any additional packages, every time you add a new package you will need to add them to your project’s
renv.lock
file by running the following coderenv::snapshot()
- Use
.github/workflows/render-and-publish-with-code.yml
as your default GitHub pages actions workflow- From your repository, rename
.github/workflows/render-and-publish.yml
torender-and-publish.yml.disabled
. Save file - From your repository, rename .github/workflows/render-and-publish-with-code.yml.disabled to
render-and-publish-with-code.yml
. Save file - Save and push all changes to GitHub, make sure the new
renv
files are pushed.render-and-publish-with-code.yml
should be the only workflow to run when changes are made to the repository
- From your repository, rename