繁体   English   中英

Paste0在Rstudio中工作,不在Rscript中工作

[英]Paste0 working in Rstudio, not in Rscript

有一个带有一些变量的字符串,我需要传递给在Rstudio中工作100%的循环,但会给我一个:

"cannot coerce type 'closure' to vector of type 'character'"

在Rscript中运行时。

smalldata <- data.frame(V1 = c(1,2,3,4,5)

tablevar <- mondaysdata


sqljoin <- paste("select * from DBO.", tablevar, " p join DBO.TABLE2 l on (p.ID1=l.ID2) where p.ID1 =", "'", row, "'", sep = " ", collapse = ",")
for(row in smalldata$V1) {
  df1 <- as.data.table(sqlQuery(con, sqljoin))
  if (nrow(df1) == 0) {
    next
  }
  df1[,function1(.SD)]
}

同样,一切在Rstudio中都可以100%正常工作,并且逐字是相同的完全相同的代码。 我在脚本顶部调用方法。 Smalldata是一列,10,000行ID字符串。 Tablevar只是我们根据日期更改的名称。 例如mondaysdata,tuesdaysdata等。

在这条线

 sqljoin <- paste("select * from DBO.", tablevar, " p join DBO.TABLE2 l on (p.ID1=l.ID2) where p.ID1 =", "'", row, "'", sep = " ", collapse = ",") 

您在定义row之前使用row row是一个函数,因此会出现错误消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM