Closed bms63 closed 7 months ago
Was the idea to replace the code
button icon to get the R
code instead of the Rmarkdown
code used to generate the page?
I was thinking inside the posit cloud installation - the entire ADSL R script would be available free of any markdown and code chunks
{knitr}
package has the purl
function that extracts R code from the .rmd files (works for .qmd as well). The documentation
argument also allows you to specify whether you want pure code (including comments) or code + markdown content as Roxygen comments.
@rossfarrugia Do we already have the posit cloud installation ready for use?
@vedhav yes - its linked on the site. from what @can-taslicukur suggests, would we just add here to our guidance a tip for users to use knitr::purl()
if they wanted to exract only the R code to run? i prefer that option than trying to maintain 2 versions of same thing or anything like that.
I'd really prefer to have the code ready for the users as a .R
file rather than .qmd
file and then telling them to run knitr::purl()
to extract the code. Wearing R-newb hat I would find that off-putting and confusing introduction to jump into.
I understand the sentiment to not maintain two files!!! I was hoping some sort of CI thing could be set up to extract the code and drop it into the user bucket on the posit cloud if possible.
ok fair, maybe better to explore a CI solution then as you say...
I think the biggest handicap of automizing the generation of .R
files with knitr::purl
is the file paths in the code.
From: https://quarto.org/docs/projects/code-execution.html#working-dir
By default, the working directory for rendering files within a project is the directory of the file itself. If you prefer to use the main project directory instead, you can add the execute-dir: project option to your config:
So one needs to set the execute_dir
and update the file paths in the quarto documents to make sure Rscripts and quarto documents run the code in the same working directory.
No further comments added from the team on this one and as I don't see it as an easy solution I'm going to say let's leave it with the current guidance of the knitr::purl()
option. I really feel like these examples are just a starter for users and they should then explore the packages themselves further, so even if they manually wanted to cut and paste the R code sections into a new script they could. In reality they're likely to be adding extra code from other places anyway to also test out, like the admiral templates/vignettes.
Extract R code from qmd files for easier running of examples