【问题标题】:R CMD check - package can be installed but not loadedR CMD检查 - 包可以安装但无法加载
【发布时间】:2016-01-15 10:38:04
【问题描述】:

我创建了一个名为letstrythis 的测试包来说明问题。测试包非常简单,包含以下文件:

  • DESCRIPTION

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

    # Generated by roxygen2: do not edit by hand
    export(add_numbers)
    
  • 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

由 roxygen2 自动创建。

每次我使用devtools::check() 检查我的包裹时,都会收到以下错误消息:

* 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
* DONE
Status: 1 ERROR

See
  'Z:/R_codes/letstrythis.Rcheck/00check.log'
for details.

Error: Command failed (1)
Execution halted

Exited with status 1.

显然,每次执行R/add-numbers.R 中的示例时,都无法使用library() 加载包。

【问题讨论】:

  • 最初该软件包位于网络驱动器上。当我将包文件夹移动到本地驱动器时,使用构建工具成功检查了包。这可能表明网络的防火墙(或其他东西......)在检查期间阻止了某些文件的安装。希望这篇笔记可能对遇到类似问题的人有所帮助。
  • 非常感谢您的评论。我遇到过同样的问题!如果您将其发布为您的问题的答案,我将不胜感激。

标签: r devtools roxygen2 r-package


【解决方案1】:

在调用library() 时设置库位置会有所帮助。在编写将要发布的一般示例时,这可能不是理想的解决方案。对我来说,在 devtools::check() 期间运行测试时很有帮助。在网络驱动器上工作时我遇到了同样的问题,即无法通过library() 加载tests/testthat.R 中指定的包。我没有将正在开发的整个包复制到本地驱动器,而是使用了命令

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

tests/testthat.R 文件中。该命令将从当前工作目录的根目录加载包。这在devtools::check() 期间很有用,因为它将使 R 使用位于临时 package_under_dev.Rcheck 文件夹中的干净包,该文件夹是在检查例程期间创建的。

或者,也可以通过

将根文件夹添加到搜索路径
.libPaths(c("..", .libPaths()))

然后不需要在对library() 的调用中指定它。在check()ing 示例的情况下,这可能会有所帮助。

按照here 的建议,玩弄R_LIBS_USER 对我没有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 2015-12-22
    • 2015-07-13
    • 2014-09-18
    • 1970-01-01
    • 2016-09-05
    相关资源
    最近更新 更多