$对原子向量无效

时间:2018-07-09 19:05:22

标签: r

当我想使用歌手姓名列表来查询API时,我不断收到错误消息Error: $ operator is invalid for atomic vectors。不过,奇怪的是,有时它确实可以工作(通常是第一次),然后在尝试将相同代码与不同/调整后的列表一起使用时,它开始显示错误代码。

################################################################################
########## This code gives you the related artists from Spotify's API ##########
################################################################################

###############################
####### needed packages #######
###############################
library(Rspotify)
library(purrr)
library(dplyr)

###############################
####### Spotify API key #######
###############################

keys <- spotifyOAuth("xxxx","xxxx","xxxx")

###################################
## Create a vector of artistnames##
###################################
names_artists <- artist_names$artist_name
names_artists

################################################################

# Create empty list
datalist = list()

## Tell loop to iterate over all entries p in track_id ##
## might need to split list into two or more ##

for(p in names_artists) {
  pl <- getRelated(p ,token=keys) %>%   # Call the function and iteration p and put it into dataframe pl
    mutate(artist_name = p)    # Use Dplyrs mutate-function to add a column with the artist name in iteration
  datalist[[p]] <- pl   # Add artist name to datalist
}

有人知道如何解决这个问题吗?

谢谢!

0 个答案:

没有答案
相关问题