R CMD check - package can be installed but not loaded

I created a test-package called letstrythis to illusttrate the problem. The test-package is very simple and consits of the following files:


    Package: letstrythis
    Title: What the Package Does (one line, title case)
    Authors@R: person("Mike", "Smith", email = "Mike.Smith@anything.com", role = c("aut", "cre"))
    Description: letstrythis is great.
        R (>= 3.2.3)
    License: GPL
    LazyData: true
    Maintainer: 'Mike Smith' <Mike.Smith@anything.com>
    RoxygenNote: 5.0.1

    # Generated by roxygen2: do not edit by hand
  • R/add-numbers.R

    #' test function
    #' @param x numeric
    #' @param y numeric
    #' @return numeric
    #' @export
    #' @examples
    #' add_numbers(1, 1)
    #' add_numbers(2, 3)
    add_numbers <- function(x, y) {
      x + y


  • man/add_numbers.Rd

which is automatically created by roxygen2.

Every time I check my package with devtools::check() I get the following error message:

* checking examples ... ERROR
Running examples in 'letstrythis-Ex.R' failed
The error occurred in:

R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> pkgname <- "letstrythis"
> source(file.path(R.home("share"), "R", "examples-header.R"))
> options(warn = 1)
> options(pager = "console")
> base::assign(".ExTimings", "letstrythis-Ex.timings", pos = 'CheckExEnv')
> base::cat("name\tuser\tsystem\telapsed\n", file=base::get(".ExTimings", pos = 'CheckExEnv'))
> base::assign(".format_ptime",
+ function(x) {
+   if(!is.na(x[4L])) x[1L] <- x[1L] + x[4L]
+   if(!is.na(x[5L])) x[2L] <- x[2L] + x[5L]
+   options(OutDec = '.')
+   format(x[1L:3L], digits = 7L)
+ },
+ pos = 'CheckExEnv')
> ### * </HEADER>
> library('letstrythis')
Error in library("letstrythis") : 
  there is no package called 'letstrythis'
Execution halted
* checking PDF version of manual ... OK
Status: 1 ERROR

for details.

Error: Command failed (1)
Execution halted

Exited with status 1.

Apperently the package cannot be loaded with library() everytime the example in R/add-numbers.R is executed.


Setting the library location in the call to library() helps. This might not be the ideal solution when writing general examples that will be published. For me, it was helpful when running tests during devtools::check(). I had the same issues when working on a network drive, i.e. packages specified in tests/testthat.R could not be loaded via library(). Instead of copying the whole package under development to a local drive I used the command

library(package_under_dev, lib.loc = "..")

in the tests/testthat.R file. The command will load the package from the root of the current working directory. This is helpful during devtools::check(), because it will make R use the clean package located in the temporary package_under_dev.Rcheck folder which is created during the checking routine.

Alternatively, one could also add the root folder to the search paths via

.libPaths(c("..", .libPaths()))

and then one doesn't need to specify it in the call to library(). Maybe this would help in case of check()ing the examples.

Playing around with R_LIBS_USER, as suggested here, did not work for me.

Need Your Help

Publish the last value of an observable

rxjs reactive-extensions-js

I have a hot observable (a subject in this case):

Button click never triggered on iPad

jquery ipad button click

I have just published first beta of a word solving app (wordfeud in spanish) and am having some issues on the iPad, hope someone can help: