R包函数导出异常:已声明导出但安装后无法调用
R包函数导出异常问题:开发环境正常但安装后无法调用
我正在开发R包spotifystreams,遇到函数导出异常:开发环境中通过devtools::load_all()可正常调用get_monthly_listeners函数,且已执行document()和test()完成更新测试,NAMESPACE文件也明确声明了该函数的导出规则。但将包通过devtools::install_github()安装到新会话后,调用函数却报错提示未导出。
函数代码
#' Get Monthly Listeners #' @export get_monthly_listeners #' @param artist_code unique 22 alpha-numeric code to identify spotify artists #' @return An integer representing total monthly streams of an artist #' @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 environment 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] #separate text from "monthly listeners" 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')
报错信息:
Error: 'get_monthly_listeners' is not an exported object from 'namespace:spotifystreams'
排查推测
推测问题可能出在devtools::install_github()未即时拉取GitHub上的最新代码,存在同步延迟。
内容的提问来源于stack exchange,提问作者Liam Haller
相关产品推荐
相关产品推荐

