2016-01-15 45 views
1

我创建了一个名为letstrythis的测试软件包来说明问题。所述检测包是非常简单和以下文件的consits:R CMD检查 - 软件包可以安装但不能加载

  • DESCRIPTION

    Package: letstrythis 
    Title: What the Package Does (one line, title case) 
    Version: 0.0.0.9000 
    [email protected]: person("Mike", "Smith", email = "[email protected]", role = c("aut", "cre")) 
    Description: letstrythis is great. 
    Depends: 
        R (>= 3.2.3) 
    License: GPL 
    LazyData: true 
    Maintainer: 'Mike Smith' <[email protected]> 
    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. 

Apperently包不能装载library()每次在R/add-numbers.R的例子被执行。

+1

该软件包最初位于网络驱动器上。当我将包文件夹移动到本地驱动器时,使用构建工具成功检查了包。这可能表示网络的防火墙(或其他内容)会阻止在检查过程中安装某些文件。希望这篇文章对遇到类似问题的人有所帮助。 –

+0

非常感谢您的评论。我遇到过同样的问题!如果您将此作为您的问题的答案发布,我很欢迎。 – Tom

回答

2

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

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

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

另外,人们还可以通过

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

添加根文件夹搜索路径,然后一个不需要在调用指定它library()。也许这对于check()例子会有帮助。

玩弄R_LIBS_USER,建议here,没有为我工作。