Running R code inside rmarkdown params in yaml

Hi,

I am creating parameterized reports and the choices of my params are coming from an R code which requires loading libraries.

When I run my code locally, it works fine even I load the libraries after the yaml part, however when I publish the RMD in RStudio Connect, I get a library error because RStudio Connect doesn't see the libraries.

Is there a way to handle this issue ?

Thanks

it seems the library configuration is wrong

@ahuoral Could you post a chunk of code that can be reproduced? Try reprex()

It seems that there is something wrong with your library paths / rprofile setup.

I had this issue with R scripts executed via cron jobs, it took inserting this code at the very top of my script to make work:

.libPaths("/usr/lib/R/site-library")

You can definitely reference code from packages in the params section of an R Markdown document. Have you tried using !r mypackage::myfunction() as the parameter value? The package has not been loaded with a library statement; its contents are not yet part of the environment.

Try something like this:

---
title: rmd with parameter that has a library dependency
params:
  hello: !r mypackage::myfunction()
---
yes. we have a dependency. `r params$hello`

Yes, I tried it, it is working locally but when I publish the Rmd on RStudio Connect (RSC), I get error as "library not found" during rendering on RSC

Please email support@rstudio.com

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.