2016-01-15 107 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,沒有爲我工作。