R 如何检查列表是否存在?

R 如何检查列表是否存在?,r,R,我正在读一个html表格。因此,有时我会得到一个列表,有时我会得到两个列表 url<-c("example.com/table") q <- html(url1) %>% html_table(fill=T) if(exists('q[[2]]')){ 我在以下两个方面都遇到了此错误: Error in q[[2]] : subscript out of bounds 如何检查列表是否存在?为什么不检查q的长度?或者某个特定元素不是空的?你试过length(q)>1@jor

我正在读一个html表格。因此,有时我会得到一个列表,有时我会得到两个列表

url<-c("example.com/table")
q <- html(url1) %>% html_table(fill=T)
if(exists('q[[2]]')){
我在以下两个方面都遇到了此错误:

Error in q[[2]] : subscript out of bounds

如何检查列表是否存在?

为什么不检查
q
的长度?或者某个特定元素不是空的?你试过
length(q)>1
@joran和chris了吗,这是一个很好的观点。非常感谢。
Error in q[[2]] : subscript out of bounds