“数据"不是从“名称空间:my_package"导出的对象 [英] 'data' is not an exported object from 'namespace:my_package'
问题描述
我正在编写一个使用外部数据的函数,如下所示:
I'm writing a function that uses an external data as follow:
首先,它检查数据是否在data
/文件夹中,如果不在,则创建data
/文件夹,然后从github下载文件;
First, it checks if the data is on the data
/ folder, if it is not, it creates the data
/ folder and then downloads the file from github;
如果数据已经在data/
文件夹中,它将读取并执行计算.
If the data is already on the data/
folder, it reads it, and perform the calculations.
问题是,当我跑步时:
devtools::check()
它返回:
Error: 'data' is not an exported object from 'namespace:my_package'
我应该手动在NAMESPACE
上放些东西吗?
Should I manually put something on NAMESPACE
?
一个例子:
my_function <- function(x){
if(file.exists("data/data.csv")){
my_function_calculation(x = x)
} else {
print("Downloading source data...")
require(RCurl)
url_base <-
getURL("https://raw.githubusercontent.com/my_repository/data.csv")
dir.create(paste0(getwd(),"/data"))
write.table(url_base,"data/data.csv", sep = ",", quote = FALSE)
my_function_calculation(x = x)
}
}
my_function_calculation <- function(x = x){
data <- NULL
data <- suppressMessages(fread("data/data.csv"))
#Here, I use data...
return(data)
}
推荐答案
在每种情况下都不尽相同,但是我已经通过删除R/
文件夹中的data.R
文件解决了该问题.
It could not be the same in every case, but I've solved the problem by removing the data.R
file on R/
folder.
data.R
是一个文件,描述了包中提供的所有数据.自从我的代码的上一版本以来,我就拥有它,它具有内置的数据,而不是远程(要下载)的数据.
删除文件解决了我的问题.
data.R
is a file describing all data presented in the package. I had it since the previous version of my code, that had the data built in, not remote (to be downloaded).
Removing the file solved my problem.
数据示例.R:
#' Name_of_the_data
#'
#' Description_of_the_Data
#'
#' @format A data frame with 10000 rows and 2 variables:
#' \describe{
#' \item{Col1}{description of Col1}
#' \item{Col2}{description of Col2}
#' }
"data_name"
这篇关于“数据"不是从“名称空间:my_package"导出的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!