working directory for compiling reports from R scripts

This answer suggests using here::here("data/mydata.csv")

But my script has extra lines that make this solution clumsy.

Is there any other way to tell RStudio to use the current working directory to compile a report?

This works:

rmarkdown::render("scripts/analysis.R", knit_root_dir=getwd())

(I would have expected this to be the default behavior for the "Compile Report" button. It works fine for .Rmd but not for .R files.)

I want to click a button instead of executing that command, to save a bit of time each time I re-compile the script over and over again.

Is there a way to make a new button in RStudio that runs whatever command I want?

Hi @slowkow

it seems that custom buttons are not supported Is it possible to customize the RStudio toolbar to add custom buttons?.

The only thing close to your request would be to provide a custom RStudio Addins which is basically an R package with some rstudio specific configuration addinexamples/inst/rstudio/addins.dcf at master · rstudio/addinexamples · GitHub .