gpt4 book ai didi

r - 采购 R6 类时如何解释错误 "elements..... must be named"?

转载 作者:行者123 更新时间:2023-12-01 08:23:34 25 4
gpt4 key购买 nike

代码片段取自 chernan's sample REST queries用于定义 R6 类的一个私有(private)方法、两个公共(public)属性和一个构造函数:

library(R6)
library(RCurl)
library(RJSONIO)
Symbol <- R6Class("Symbol",
private = list(
#
# define a generic function to send an HTTP GET request
#
rcurl_request <- function(service_url, parameters) {
# Collapse all parameters into one string
all_parameters <- paste(
sapply(names(parameters),
FUN=function(param_name, parameters) {
paste(param_name, paste(parameters[[param_name]], collapse=','), collapse='', sep='=')
},
parameters),
collapse="&")
# Paste base URL and parameters
requested_url <- paste0(service_url, all_parameters)
# Encode URL (in case there would be any space character for instance)
requested_url <- URLencode(requested_url)
# Start request to service
response <- getURL(requested_url, .opts = list(ssl.verifypeer = FALSE))
return(response)
}
),
public = list(
species = NULL,
bdbnJSON = NULL,
initialize = function(symbol, bdbSpecies){
parameters <- list(method="dbfind",
inputValues=symbol,
output="geneid",
taxonId=bdbSpecies,
format="col"
)
base_url = "https://biodbnet-abcc.ncifcrf.gov/webServices/rest.php/"
json_url = paste0(base_url, "biodbnetRestApi.json?")
self$bdbnJSON <- rcurl_request(json_url, parameters)
}
)
)

现在我获取包含文件并得到一个奇怪的错误。
> source("parseSymbol.R")
Error in R6Class("Symbol", private = list(rcurl_request <- function(service_url, :
All elements of public, private, and active must be named.

这看起来应该意味着我试图做一些类似“self$[我没有在公共(public)或私有(private)中声明的东西] <- new value”之类的东西,但似乎没有这样的错误。这里发生了什么?

最佳答案

您必须使用 = list 中的运算符而不是 <- .
所以在你的情况下使用 rcurl_request = function(service_url, parameters) {解决问题。

错误消息不是很丰富,我已经多次遇到这个问题。

关于r - 采购 R6 类时如何解释错误 "elements..... must be named"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45383616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com