Liam Haller
Liam Haller

Reputation: 312

"Function" is not an exported object from "Package"

I am attempting to develop a package and am having trouble exporting functions from the package.

My issue is that despite the fact that the functions are clearly visible in my packages NAMESPACE function, and after having updated and tested the packaged with document() and test(), when I download the package and attempt to run the function in another session I get the following error error

Error: 'get_monthly_listeners' is not an exported object from 'namespace:spotifystreams'

On the session with the package in development I had no problem running the following function from the package after using 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')

But after downloading the package and attempting to run the same function, I get the error that no functions from within the package are exported.

devtools::install_github("liamhaller/spotifystreams", force = TRUE)
library(spotifystreams)

spotifystreams::get_monthly_listeners('13y7CgLHjMVRMDqxdx0Xdo')

This is the namespace in question: https://github.com/liamhaller/spotifystreams/blob/main/NAMESPACE

And associated function from the package: https://github.com/liamhaller/spotifystreams/blob/main/R/get_monthly_listeners.R

Edit: After giving it some time it appears as if the issue might be with devtools::install_github() not updating the version that is hosted on github immediately. The version of the code that is currently being loaded into the install_github() package appears not to have incorporated the most up-to-date changes and is an hour old. I suspect there might be some delay with the version that install_github() downloads

Upvotes: 3

Views: 645

Answers (1)

Till
Till

Reputation: 6628

You don't need to add the function name after "@export". Try the below:

#' 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 %>%
#' @export
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')

Upvotes: 2

Related Questions