I know this is a bit of an older question, but for others out there, there is a way to code the .Rproj in a script.
If you look at the devtools::create
function, there is a function called use_rstudio
. Looking at the contents of that function you get:
> devtools::use_rstudio
function (pkg = ".")
{
pkg <- as.package(pkg)
path <- file.path(pkg$path, paste0(pkg$package, ".Rproj"))
if (file.exists(path)) {
stop(pkg$package, ".Rproj already exists", call. = FALSE)
}
message("Adding RStudio project file to ", pkg$package)
template_path <- system.file("templates/template.Rproj",
package = "devtools")
file.copy(template_path, path)
add_git_ignore(pkg, c(".Rproj.user", ".Rhistory", ".RData"))
add_build_ignore(pkg, c("^.*\\.Rproj$", "^\\.Rproj\\.user$"),
escape = FALSE)
invisible(TRUE)
}
<environment: namespace:devtools>
See the section for template_path
? That is the code you can use to create the .Rproj
file. So the end code in the script would be:
path <- file.path('path/to/folder', paste0('foldername', ".Rproj"))
template_path <- system.file("templates/template.Rproj",
package = "devtools")
file.copy(template_path, path)
You can now create an .Rproj
from code! :)