R $对于原子向量无效
我一直收到错误消息R $对于原子向量无效,r,R,我一直收到错误消息error:$operator对原子向量无效,同时希望使用艺术家姓名列表来查询API。但奇怪的是,有时它确实起作用(大部分是第一次),然后在尝试将同一代码与不同/调整的列表一起使用时,它开始显示错误代码 ################################################################################ ########## This code gives you the related artists from Sp
error:$operator对原子向量无效
,同时希望使用艺术家姓名列表来查询API。但奇怪的是,有时它确实起作用(大部分是第一次),然后在尝试将同一代码与不同/调整的列表一起使用时,它开始显示错误代码
################################################################################
########## 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
}
################################################################################
##########此代码为您提供Spotify API中的相关艺术家##########
################################################################################
###############################
#######需要的包裹#######
###############################
图书馆(Rspotify)
图书馆(purrr)
图书馆(dplyr)
###############################
#######SpotifyAPI密钥#######
###############################
键$
运算符仅适用于recursirve对象(列表,从列表生成的数据帧…),您确定artists2
始终为您提供数据帧吗?您的错误是因为$
应用于一维向量(请在前面使用str()
和is.atomic()
进行检查),它确实不是递归的,但出于某些原因,该代码确实可以工作,有时也会工作(……我知道这很奇怪)。如果我使对象递归(例如列表),函数将停止工作,并在is.url(url):length(url)==1中显示错误}
-如果您对此有解决方案,我也会很高兴;-)艺术家姓名的类型和输出是什么?从变量名来看,它似乎不是一个2D向量。艺术家命名对象的类型是一个列表。