-
-
Notifications
You must be signed in to change notification settings - Fork 978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Absolute ggplot graph file path generated using rmarkdown::render() #2365
Comments
Hi @erikaduan ! There is several things in this issue I think.
You are explicitly overwriting your YAML header configuration for output by providing a output format function in
When you render on your local environment which seems to be Windows, the windows absolute path is used. when you render on Github action, you are not using windows but ubuntu so a Linux absolute path scheme is used. Hence the difference. But at the end, the issue is the same, it is using a absolute path. So what about this absolute file path? I think you are encountering this issue : #2024 Unfortunately, this is not an easy issue and the paths handling from within Several hints:
Doing something like this would probably we working as you are expecting for (i in 1:nrow(params_df)) {
temp_output <- xfun::from_root("code", "output")
fs::dir_create(temp_output)
rmarkdown::render(
input = xfun::from_root("code", "02_create_report_template.Rmd"),
output_format = github_document(html_preview = FALSE),
params = list(sex = params_df[i, 1],
measure = params_df[i, 2]),
output_file = xfun::from_root(temp_output, glue::glue("{params_df[i, 1]}_{params_df[i, 2]}_report.md"))
)
fs::dir_copy(temp_output, xfun::from_root("output"), overwrite = TRUE)
fs::dir_delete(temp_output)
} This could even be simplified if you would do all the rendering locally in the code folder (by executing the R script using I hope it helps |
Duplicate of #2024 |
Thanks so much for solving both questions so quickly @cderv. The explanations and code solution was extremely helpful. An interesting observation I made was that the code you suggested causes I ended up using your suggestion to use
|
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
Checklist
When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:
formatted your issue so it is easier for us to read?
included a minimal, self-contained, and reproducible example?
pasted the output from
xfun::session_info('rmarkdown')
in your issue?upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?
installed and tested your bug with the development version of the rmarkdown package using
remotes::install_github("rstudio/rmarkdown")
?Issue details
I am trying to create a tutorial on how to automate R report generation and have created a contained project at https://github.com/erikaduan/abs_labour_force_report.
I have created an R markdown report template here, which outputs a ggplot graph. When I render this report template directly, the github document contains the correct relative figure path to display my ggplot graph.
I then attempt to render this template using a list of YAML parameters with another script here.
It generates the set of reports by parameters of interest, but the output path for my ggplot graph seems to no longer be relative in the rendered github document (an example here).
The problem seems to be the generation of
/home/runner/work/abs_labour_force_report/abs_labour_force_report/
, which is a new observation for me.I am trying to minimise the number of packages to load, by not using
tidyverse
and using individual packages and my renv lockfile is here. I'm wondering if this has contributed to this problem, but it doesn't make sense that the original report template can successfully render.A second minor observation is that html documents are also rendered in my output directory despite adding the code below to my report template.
Many thanks in advance!
Update: The absolute file path first generated is my local file path i.e.
![](C:/Users/Erika/OneDrive/Desktop/git_repos/abs_labour_force_report/output/all_full-time_report_files/figure-gfm/unnamed-chunk-2-1.png)
, which then gets overwritten into![](/home/runner/work/abs_labour_force_report/abs_labour_force_report/output/female_full-time_report_files/figure-gfm/unnamed-chunk-2-1.png)
when my GitHub Actions YAML pipeline runs. Not sure if this helps.Session info
The text was updated successfully, but these errors were encountered: