R 错误在<;我的代码>;:类型为'的对象;关闭';不可再附加
我终于能够算出的代码。它似乎工作正常,然后当我再次运行它时,突然收到以下错误消息:R 错误在<;我的代码>;:类型为'的对象;关闭';不可再附加,r,r-faq,R,R Faq,我终于能够算出的代码。它似乎工作正常,然后当我再次运行它时,突然收到以下错误消息: Error in url[i] = paste("http://en.wikipedia.org/wiki/", gsub(" ", "_", : object of type 'closure' is not subsettable 我不知道为什么,因为我没有在代码中更改任何内容 请告知 library(XML) library(plyr) names <- c("George Clooney
Error in url[i] = paste("http://en.wikipedia.org/wiki/", gsub(" ", "_", :
object of type 'closure' is not subsettable
我不知道为什么,因为我没有在代码中更改任何内容
请告知
library(XML)
library(plyr)
names <- c("George Clooney", "Kevin Costner", "George Bush", "Amar Shanghavi")
for(i in 1:length(names)) {
url[i] = paste('http://en.wikipedia.org/wiki/', gsub(" ","_", names[i]) , sep="")
# some parsing code
}
库(XML)
图书馆(plyr)
名称在尝试将其子集之前,您不需要定义向量url
url
也是基本包中的一个函数,因此url[i]
正在尝试将该函数子集。。。这没有道理
您可能在以前的R会话中定义了url
,但忘记将该代码复制到脚本中。通常,此错误消息表示您试图对函数使用索引。您可以复制此错误消息,例如
mean[1]
## Error in mean[1] : object of type 'closure' is not subsettable
mean[[1]]
## Error in mean[[1]] : object of type 'closure' is not subsettable
mean$a
## Error in mean$a : object of type 'closure' is not subsettable
错误消息中提到的闭包是(松散地)函数和调用函数时存储变量的环境
在这个特定的例子中,正如Joshua所提到的,您试图将函数作为变量访问。如果定义一个名为url
的变量,则错误消失
作为一个好的实践,您通常应该避免在base-R函数之后命名变量。(调用变量是此错误的常见原因。)
尝试子集运算符或关键字时会出现几个相关错误
`+`[1]
## Error in `+`[1] : object of type 'builtin' is not subsettable
`if`[1]
## Error in `if`[1] : object of type 'special' is not subsettable
如果您在shinny
中遇到此问题,最有可能的原因是您试图使用反应式
表达式,而不使用括号将其作为函数调用
library(shiny)
reactive_df <- reactive({
data.frame(col1 = c(1,2,3),
col2 = c(4,5,6))
})
但如果我们试图在没有括号的情况下对其进行子集,那么我们实际上是在尝试索引一个函数,我们会得到一个错误:
isolate(
reactive_df$col1
)
Error in reactive_df$col1 : object of type 'closure' is not subsettable
我想你是想做url[I]我遇到了这个问题,当时我试图删除事件中的ui元素:
myReactives <- eventReactive(input$execute, {
... # Some other long running function here
removeUI(selector = "#placeholder2")
})
myReactives如果出现类似错误
警告:类型为“closure”的$:对象中的错误不可子集
[没有可用的堆栈跟踪]
只需使用以下命令添加相应的包名:
e、 g
而不是标记(…)
写
闪亮::标记(..)它可能意味着一个未定义的变量。在我的例子中,当您错误地键入[]
而不是()
时,也会发生这种情况!
myReactives <- eventReactive(input$execute, {
... # Some other long running function here
removeUI(selector = "#placeholder2")
})