How to organize Rmarkdown files (with brilliant runtime) inside a package
I currently have an analysis project that I was treating as a package. Therefore, I currently have the following structure:
mycoolanalysispackage/
|-- .Rbuildignore
|-- .gitignore
|-- DESCRIPTION
|-- NAMESPACE
|-- inst
|-- vignettes
|-- R
`-- mycoolanalysispackage.Rproj
In the end, I usually make a lot of brilliant applications like Rmarkdown-flexdashboard with brilliant execution times.
-- app1/
|-- index.Rmd
-- app2/
|-- index.Rmd
My question is, which package subdirectory should I put these application directories (along with my files index.Rmd
)?
I also have a local Shiny Server , what's the best way to link this Rmarkdown-flexdashboard app to this server?
source to share
As with everything else, you place them in a subfolder inst
when you design the package. When a package is installed, all the folders in the folder inst
will be moved to the package folder and therefore can be used as subfolders. So
mycoolanalysispackage/
|-- .Rbuildignore
|-- .gitignore
|-- DESCRIPTION
|-- NAMESPACE
|-- inst
|-- app1/
|-- index.Rmd
|-- etc...
|-- R
`-- mycoolanalysispackage.Rproj
To access files from an R function, you can use system.file
:
system.file("app1","index.Rmd",package = "mycoolanalysispackage")
will give you the exact path to the index.Rmd of the app1. This result can then be used to deploy the application using the appropriate functionality.
See also the Writing R Extensions guide (scroll down a bit)
source to share