简体   繁体   中英

Setup for R package development (Process and build chain)

I am trying to figure out how the R development process using RStudio (and Windoze) should look in case I want to customize an existing package for personal use. So let's say there is package X (which I have installed using packages.install from cran/rforge whatever) with function y which I use from within my function z (in some file ~/myRFile.R).

So what I would have done is the following:

  1. Remove the installed package (using remove.packages(X))
  2. Fetch the source from rforge/github etc. and save it in ~/downloadedPackage.
  3. Now I am starting to struggle what I have to do next. What's the best way link my existing file (~/myRFile.R) to the source in ~/downloadedPackage? I know I could probably figure out in which R file function y was and load it using source("~/downloadedPackage/theFileWithFunctionY.R") but I cannot imagine that this is the right way to do so, or is it? I would imagine there is a way to "load"/"source" all the code at once? What I also tried was just to use

    install.packages("~\\downloadedPackage")

    library(downloadedPackage)

but this just gives me "installing package... warning package is not available (as binary package for R...)". Furthermore I assume that installing the package everytime a small change is made during the development process is suboptimal anyways (for instance I guess it would be much harder to debug the code once it is installed).

So I am not really looking for step by step instructions on how to build a package, but rather on the big picture of how to set up the optimal process and toolchain in order to

  1. modify
  2. test
  3. reinstall

an existing R package.

Btw: I am most familiar with the Java buildtools/process in case it is easier to explain it by reference to another set of buildtools (javac, ant, maven, gradle, etc.).

Three solutions:

  1. You can install an R package from source with

     install.packages(path_to_file, repos = NULL, type="source") 
  2. You can install it through RStudio. Do File->New Project in RStudio, and open that directory as an R project. Clicking "Build and Reload" (under the Build tab) will reinstall the package (see here for more). Having it open in RStudio makes the "make changes/reinstall" loop very straightforward.

  3. If you want to load the package without installing it, you could install the devtools package , and use load_all :

     devtools::load_all("~/downloadedPackage") 

    This has the added benefit of happening a bit faster than reinstallation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM