Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

devtools equivalent of RStudio Build panel buttons

I am making an R package using RStudio. I am comfortable using the buttons on the Build panel. I have a script that I would like to run each time I Build & Reload or Clean and Rebuild. I'd like to write a function that runs my script and then executes the devtools commands associated with one of those buttons, but I am having trouble finding documentation of the correspondence between those buttons and devtools commands. The buttons are as follows:

  • Build & Reload
  • Check
  • Load All
  • Clean and Rebuild
  • Test Package
  • Check Package
  • Build Source Package
  • Build Binary Package

For each of the items in that list, what devtools R code would I run to cause the exact same behavior?

like image 215
Paul de Barros Avatar asked May 25 '17 15:05

Paul de Barros


2 Answers

In RStudio you can check "Use devtools package functions if available" in Project Options > Build Tools and you can see what devtools functions will be used. If you look at the build console pane, you can check out what RStudio runs. General cases if using devtools:

  • Build & Reload

    • devtools::build()
    • devtools::reload() is possibly an option but Rstudio uses R CMD INSTALL --no-multiarch --with-keep.source <pkgNameGoesHere>
  • Check

    • devtools::check()
  • Load All
    • devtools::load_all(".")
  • Clean and Rebuild
    • R CMD INSTALL --preclean --no-multiarch --with-keep.source <pkgNameGoesHere>
  • Test Package
    • devtools::test()
  • Check Package
    • devtools::check() (same as Check button)
  • Build Source Package
    • devtools::build()
  • Build Binary Package
    • devtools::build(binary = TRUE, args = c('--preclean'))

More info at the readme in the devtools repo.

like image 85
Michael Kirchner Avatar answered Sep 30 '22 16:09

Michael Kirchner


To execute the Clean & Rebuilt action from RStudio inside R you can use the R function system() Executing

system("R CMD INSTALL 
--preclean 
--no-multiarch 
--with-keep.source <your_package_name>")

Executes the Shell command from within your R session. Be aware that you will have to refer to the correct location of your package if you run this outside the Package Project (e.g. from another project or session)

like image 34
Maddocent Avatar answered Sep 30 '22 15:09

Maddocent