2014-09-29 133 views
16

我有一個R包,我一直在RStudio中構建,我們稱之爲my_pkg。當我運行中RStudio devtools::load_all(".")(特別是使用Ctrl + Shift + L快捷方式),我得到以下信息:字符(0)在RStudio中運行devtools :: load_all(「。」)時出現警告

Loading my_pkg 
Warning messages: 
1: character(0) 
2: character(0) 
3: character(0) 
4: character(0) 
5: character(0) 

在包做工精細功能的全部。我的NAMESPACEDESCRIPTION文件完整,沒有語法錯誤。但是,運行?my_pkg時,幫助文件與DESCRIPTION文件中提供的規格不符。當我從DESCRIPTION中刪除Imports時,不再有character(0)警告消息。當然,我需要這些進口。當我將Imports更改爲Suggests時,有character(0)警告消息。

以下是描述文件內容,其中一些內容已更改爲保護IP。

Package: scoutdroid 
Title: This is where the title is. 
Version: 0.1 
[email protected]: "Ben Hanowell <[email protected]> [aut, cre]" 
Description: This is where the description is. 
Depends: 
    R (>= 3.1.0) 
Imports: 
    dplyr, 
    lubridate, 
    mboost, 
    randomForestSRC, 
    RODBC, 
    stringr 
License: file LICENSE 
LazyData: true 

這裏是NAMESPACE

# Generated by roxygen2 (4.0.1): do not edit by hand 

import(RODBC) 
import(dplyr) 
import(lubridate) 
import(mboost) 
import(parallel) 
import(randomForestSRC) 
import(stringr) 

當我使用RStudio建立在Build標籤&刷新按鈕,我得到以下警告:

**準備包延遲加載

Warning: replacing previous import by 'lubridate::intersect' when loading 'scoutdroid' 
Warning: replacing previous import by 'lubridate::setdiff' when loading 'scoutdroid' 
Warning: replacing previous import by 'lubridate::union' when loading 'scoutdroid' 

編輯增加了一些更多細節可以幫助人們瞭解可能發生的事情。

編輯2我還添加了DESCRIPTION文件,但我沒有提供完整的包,這是專有的。

編輯3增加NAMESPACE

編輯4添加了在生成選項卡中使用RStudio Build &重新加載按鈕時發生的警告。

+0

是你在github上的軟件包 – Dason 2014-09-29 16:21:56

+0

不是。它是專有的。 *編輯*它在Bitbucket上,但訪問是私人的。 – 2014-09-29 16:48:26

+1

祝你好運。也許你可以嘗試做一個最小可重現的例子。 – Dason 2014-09-29 17:27:42

回答

16

在註釋中出現一些對話框後,我們發現load_all給您的空警告實際上是在由於函數名稱衝突而加載包時啓動的。

問題是您要從包中導入函數,然後覆蓋該函數。出現這種情況時,你看到的,當你點擊「生成&刷新」在RStudio [R拋出警告:

Warning: replacing previous import by 'lubridate::intersect' when loading 'scoutdroid' 
Warning: replacing previous import by 'lubridate::setdiff' when loading 'scoutdroid' 
Warning: replacing previous import by 'lubridate::union' when loading 'scoutdroid' 

它看起來像load_all可能試圖馬弗這些警告(只是猜測),這就是爲什麼你看到character(0)代替的實際警告。 (這些特定的警告很難保持沉默。)

導入整個包的命名空間通常不是一個好主意。您應該只導入您需要的符號。請參閱我的this post瞭解更多。

解決方法是在您的NAMESPACE文件中使用importFrom而不是import

+1

對於其他人來這裏尋找解決方案。當你運行'devtools :: check'時,上面的警告將會顯示 – adibender 2017-09-06 11:39:53