0

I am using a wrapper for the LastFM API to search for track Tags. the wrapper function is...

devtools::install_github("juyeongkim/lastfmr")  

track_getInfo("track", "artist", api_key= lastkey)

I defined my own function as

   INFOLM <- function(x= track, y= artist) {  
    output <- track_getInfo(x,y,api_key = lastkey)   
     output <- flatten(output)  
     output_1 <- output[["tag"]][["name"]]   
     return(output_1)
     }

Then prepared my list elements from my larger data frame

artist4lf <- c(small_descriptive[1:10,2])  
track4lf <- c(small_descriptive[1:10,3])  
x<- vector("list", length = length(track4lf))  
y<- vector("list", length = length(artist4lf))  
names(x) <- track4lf  
names(y) <- artist4lf

Then...

map2_df(track4lf, artist4lf, INFOLM)

I get a 0x0 tibble back everytime... does anyone have a suggestion?

MrFlick
  • 195,160
  • 17
  • 277
  • 295
danni.j.t
  • 15
  • 3
  • 1
    Have you tested that your function works outside of a `map` call? Like if you just call `INFOLM("some track name", "some artist")`? – camille Jul 09 '18 at 20:05
  • 1
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jul 09 '18 at 20:07

1 Answers1

0

I think your INFOLM function will work if you just delete the api_key argument from the track_getInfo function.

Also, not sure you need to use purrr::map2 here, you should be able to use your small_descriptive dataframe with rowwise and mutate to add the column(s) you want.

Here's a go, using testdf as if it's your small_descriptive dataframe with only the track and artist columns.

library(lastfmr)
library(dplyr)
library(tidyr)

testdf <- tribble(
     ~Artist, ~Track,
     "SmashMouth", "All Star",
     "Garth Brooks", "The Dance"
)


INFOLM <- function(x= track, y= artist) {  
     output <- track_getInfo(x,y)   
     output <- flatten(output)  
     output_1 <- output[["tag"]][["name"]]   
     return(paste(output_1, collapse = ","))
}

testdf %>% rowwise %>% 
     mutate(stuff = INFOLM(Track, Artist)) %>% 
     tidyr::separate(stuff, c("Tag1", "Tag2", "Tag3", "Tag4", "Tag5"), sep = ",")
TBT8
  • 766
  • 1
  • 6
  • 10
  • Although, I just tried to increase my data frame from 10 to 100 and go this error: "Error in mutate_impl(.data, dots) : Evaluation error: Track not found (ERROR 6).." – danni.j.t Jul 09 '18 at 21:12
  • I think that would indicate one of the track names in your `small_descriptive` dataframe is not in the lastfmr database. – TBT8 Jul 11 '18 at 16:24