Create R package without an Rstudio project file using `devtools::create`

When inside RStudio desktop, I run

devtools::create('foobar', rstudio = FALSE)

I still get an RStudio project file inside the directory.

If I run

Rscript -e "devtools::create('foobaz')"

on my (Linux) terminal, then no project file is created.

It seems like rstudioapi::isAvailable() is being run and if that gives TRUE (when inside RStudio desktop) or FALSE (when in the terminal) that determines whether I get the project file.

The devtools::create calls usethis::create_package and there we have an argument rstudio. The help for that argument says
If TRUE, calls use_rstudio() to make the new package or project into an RStudio Project. If FALSE and a non-package project, a sentinel .here file is placed so that the directory can be recognized as a project by the here or rprojroot packages.

So why does

devtools::create('foobar', rstudio = FALSE)

give a project file?

I usually want a project file. But I want to understand if I am doing something wrong.

1 Like

I was able to replicate this.

The issue is the argument open = interactive(). When you run this in an interactive RStudio session, it calls proj_activate(), which then calls rstudioapi::openProject() (if rstudioapi::isAvailable() is TRUE). Thus to avoid this, you'll need to set open = FALSE. Note that this will also result in the working directory not changing.

devtools::create('foobar', rstudio = FALSE, open = FALSE)

And it turns out this has also been discussed in the usethis GitHub Issue create_package does not behave as documented regarding the rstudio argument. And the advice is the same: set open = FALSE.

2 Likes

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