我正在尝试开发一个软件包,但在从软件包导出函数时遇到问题。
我的问题是,尽管事实上,函数是清晰可见的,在我的包NAMESPACE函数,并更新和测试后,与文档()和测试(),当我下载包,并试图运行函数在另一个会话我得到以下错误错误
Error: 'get_monthly_listeners' is not an exported object from 'namespace:spotifystreams'
在与开发中的包的会话中,我在使用load_all()后从包中运行以下函数没有问题
#' Get Monthly Listeners
#' @export get_monthly_listeners
#' @param artist_code unique 22 alpha-numeric code to identify spotify artists
#' @return An integer represetning total monthly streams of an artists
#' @importFrom rvest read_html html_elements html_text
#' @importFrom dplyr %>%
get_monthly_listeners <- function(artist_code){
#Spotify link to artists page
artist_url <- paste0("https://open.spotify.com/artist/", artist_code)
#Load html data from spotify page in enviroment
web <- rvest::read_html(artist_url)
#select all text within div content
div_content <- web %>% rvest::html_elements("div") %>% rvest::html_text()
#10th item in the vector contains stream info
monthly_streams <- div_content[10]
#seperate text from "monthly listerers"
monthly_streams <- strsplit(monthly_streams, split = " ")
#subset list, and then vector to get first element
monthly_streams <- monthly_streams[[1]][1]
#remove the comma so we can convert to numeric
monthly_streams <- as.numeric(gsub(",", "", monthly_streams))
return(monthly_streams)
}
get_monthly_listeners('13y7CgLHjMVRMDqxdx0Xdo')
但是在下载包并尝试运行相同的函数后,我得到了一个错误,即包中没有导出任何函数。
devtools::install_github("liamhaller/spotifystreams", force = TRUE)
library(spotifystreams)
spotifystreams::get_monthly_listeners('13y7CgLHjMVRMDqxdx0Xdo')
这里是问题名称空间:https://github.com/liamhaller/spotifystreams/blob/main/NAMESPACE
以及包中关联函数:https://github.com/liamhaller/spotifystreams/blob/main/R/get_monthly_listeners.R
编辑:经过一段时间后,问题似乎是devtools::install_github()没有立即更新github上托管的版本。当前加载到install_github()包中的代码版本似乎没有包含最新的更改,并且是一个小时前的版本。我怀疑install_github()下载的版本可能会有一些延迟
1条答案
按热度按时间zf9nrax11#
您不需要在“@export”之后添加函数名。尝试以下操作: