-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Q: calling functions in dplyr pipelines #171
Comments
Heya, digging around in the issues a bit I stumbled upon this resource: https://mirr.netlify.app/audio-features-spotify.html mentioned in #76, which works wonderfully: df <- tribble(
~track, ~artist, ~album,
"Move This", "Technotronic", "Pump Up the Jam: The Album",
"Amy's Theme", "Murray Gold", "Doctor Who: Series 5",
)
track_spotify_id <- function(artist, track, album, type = c("track")) {
search_results <- search_spotify(glue("artist:{artist} track:{track} album:{album}"), type = type)
return(search_results$id[[1]])
}
possible_search <- possibly(track_spotify_id, otherwise = 0)
df %>%
mutate(album = gsub('\\:.*', "", album)) %>% # if album contains a colon, take only the first substring up to it
mutate(sid = pmap(list(artist, track, album), possible_search)) %>%
unnest(sid) Some of my album-data is bogus, so I''ll have to implement a fallback search sans-album in |
Well, I think that we are talking about different issues here. If you want to do some programming that involves tibbles (data.frames) as opposed to vectors, we are not talking about a dplyr but a purrr pipeline, and instead of the mutate() function you would likelly use some version of map(). The other thing that you are mentioning is a kind of a type mismatch. The idea why we use vapply instaed of lapply or sapply is exactly because vapply throws an error if the result has an unexpect dimension or class, or some unexpected coercion takes place. So if you can place here a reproducible error that gives a vapply error, I can look into it. If you want to use spotifyr in a tidy workflow, I think that you must work with purrr. |
Thanks for your reply! Indeed, I understand now that purrr is required, the snippet above involves As stated in the original post, I don't believe there is an error here, more of a confusion on my side as to how to join spotifyr and the tidyverse correctly, given the popularity of both. |
Hi all, and many thanks for creating and maintining this package in a very welcoming spirit!
This is a question, not an issue per se, although I'd gladly send a PR to the Readme once this is figured out.
Is it possible to use functions exported by this package, e.g.
search_spotify()
, in dplyr pipelines?I have a dataset containing triples of
(track, artist, album)
, and I would like to load these into a tibble, then pipe each row tosearch_spotify
and aggregate the result:Unfortunately, this throws me:
I tried using the exposition pipe
%$%
to no avail:... which results in:
I'm missing something, but I can't put my finger on what it is. Any clues?
Cheers!
Edit:
For sake of completeness, I'm using 2.2.3 from CRAN
The text was updated successfully, but these errors were encountered: