Although we’ll build a very simple package, we’ll use the most modern and powerful tools for R package development. In theory, this could eventually involve compiling C/C++ code, which means you need what’s called a build environment.
back to All the package things
Embarking on your career as an R package developer is an important milestone. Why not celebrate by updating R and RStudio? This is something we recommended early and we recommend doing it often. Go back to Day 0 of the course for reminders on the process. DO IT NOW. We are not very interested in solving problems that stem from running outdated versions of R and RStudio.
2016-11 FYI: Jenny is running R version 3.3.1 (2016-06-21) Bug in Your Hair and RStudio 1.0.44 at the time of writing.
We use the
devtools package to help us develop our R package. Do this:
You will probably get an immediate warning from
devtools, complaining that you need
Rtools in order to build R packages.
You can ignore this and successfully develop an R package that consists solely of R code. Such as our toy package.
However, we recommend you install Rtools, so you can take full advantage of
devtools. Soon, you will want to use
devtools::install_github() to install R packages from GitHub, instead of CRAN. You will inevitably need to build a package that includes C/C++ code, which will require Rtools.
Rtools is NOT an R package but is rather “a collection of resources for building packages for R under Microsoft Windows, or for building R itself”.
Go here and do what it says:
Rtools installation you will get to a window asking you to “Select Additional Tasks”. It is important that you make sure to select the box for “Edit the system PATH”.
Are we going to recommend making sure Git Bash is NOT on
PATH? See #230.
Rtools, restart RStudio, then do:
Hopefully you will simply see a message saying
TRUE, indicating that
Rtools is properly installed. But if there was a problem, you will see a longer message with next steps.
You will not get an immediate warning from
devtools that you need to install anything. But before you can build R package with compiled code, you will also need to install more software. Pick one:
devtools offers a diagnostic function to check if your system is ready.
Hopefully you see
Install more packages. If you already have them, update them.
2016-11 FYI: Jenny is running these versions of this packages at the time of writing.
#> #> Attaching package: 'dplyr' #> The following object is masked from 'package:testthat': #> #> matches #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union #> package * version date source #> 1 devtools * 126.96.36.19900 2016-11-23 local #> 2 knitr * 1.14.2 2016-09-07 Github (yihui/knitr@f02600d) #> 3 roxygen2 * 188.8.131.5200 2016-10-23 Github (klutometis/roxygen@9ffbad0) #> 4 testthat * 184.108.40.20600 2016-09-09 Github (hadley/testthat@46d15da)
How to check which version of a specific package you’ve got installed:
How to install a package and all it’s dependencies:
install.packages("devtools", dependencies = TRUE)
See how profound your problem with out-of-date packages is:
Update one package:
Just update everything:
update.packages(ask = FALSE)
CAVEAT: The above examples will only consult your default library and default CRAN mirror. If you want to target a non-default library, use function arguments to say so. Packages that you have installed from GitHub? You’ll need to check the current-ness of your version and perform upgrades yourself.
We aren’t using bleeding edge features of
devtools, but you could upgrade to the development version of
devtools at this point.
Mac and Linux users have it easy. Do this:
For Windows instructions, see the
back to All the package things