Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过shell vs.rstudio调用时脚本未运行,会生成在gui中运行时无法获得的r错误_R_Linux_Shell_Rstudio Server - Fatal编程技术网

通过shell vs.rstudio调用时脚本未运行,会生成在gui中运行时无法获得的r错误

通过shell vs.rstudio调用时脚本未运行,会生成在gui中运行时无法获得的r错误,r,linux,shell,rstudio-server,R,Linux,Shell,Rstudio Server,我不确定这是否是一个r或shell问题,请原谅添加两个标记,如果您认为我应该删除一个,请评论,我会这样做 我在rstudio.example.com上有一个亚马逊托管的r版本。我已经编写了两个脚本,当我从Rstudio接口中获取它们时,它们都运行良好 当我ssh到脚本目录并从那里运行时,脚本会生成一些错误 第一个脚本的目的是检查数据帧中一列文本的拼写,然后获取该拼写错误的频率以及拼错单词的示例: library(tidyverse) library(qdap) # example data ex

我不确定这是否是一个r或shell问题,请原谅添加两个标记,如果您认为我应该删除一个,请评论,我会这样做

我在rstudio.example.com上有一个亚马逊托管的r版本。我已经编写了两个脚本,当我从Rstudio接口中获取它们时,它们都运行良好

当我ssh到脚本目录并从那里运行时,脚本会生成一些错误

第一个脚本的目的是检查数据帧中一列文本的拼写,然后获取该拼写错误的频率以及拼错单词的示例:

library(tidyverse)
library(qdap)
# example data
exampledata <- data.frame(
  id = 1:5,
  text = c("cats dogs dgs cts oranges",
           "orngs orngs cats dgs",
           "bannanas, dogs",
           "cats cts dgs bnnanas",
           "ornges fruit")
)

# check for unique misspelt words using qdap
all.misspelts <- check_spelling(exampledata$text) %>% data.frame %>% select(row:not.found)
unique.misspelts <- unique(all.misspelts$not.found)

# for each misspelt word, get the first instance of it appearing for context/example of word in a sentence
contexts.misspellts.index <- lapply(unique.misspelts, function(x) {
  filter(all.misspelts, grepl(paste0("\\b",x,"\\b"), not.found))[1, "row"]
}) %>% unlist

# join it all together in a data farem to write to a csv
contexts.misspelts.vector <- exampledata[contexts.misspellts.index, "text"]
freq.misspelts <- table(all.misspelts$not.found) %>% data.frame() %>% mutate(Var1 = as.character(Var1))
misspelts.done <- data.frame(unique.misspelts, contexts.misspelts.vector, stringsAsFactors = F) %>%
  left_join(freq.misspelts, by = c("unique.misspelts" = "Var1")) %>% arrange(desc(Freq))
write.csv(x = misspelts.done, file="~/csvs/misspelts.example_data_done.csv", row.names=F, quote=F)
当我在我的RStudio云实例上运行它时,它不会出现任何问题,并且会在最后一行代码中指定的目录中生成一个csv文件

在linux中运行此操作时,我得到:

myname@ip-10-0-0-38:~$ r myscript.R


    ident, sql

During startup - Warning message:
Setting LC_CTYPE failed, using "C" 
During startup - Warning message:
Setting LC_CTYPE failed, using "C" 
During startup - Warning message:
Setting LC_CTYPE failed, using "C" 
During startup - Warning message:
Setting LC_CTYPE failed, using "C" 
During startup - Warning message:
Setting LC_CTYPE failed, using "C" 
During startup - Warning message:
Setting LC_CTYPE failed, using "C" 
During startup - Warning message:
Setting LC_CTYPE failed, using "C" 
During startup - Warning message:
Setting LC_CTYPE failed, using "C" 
Error in grepl(paste0("\\b", x, "\\b"), not.found) : 
  object 'not.found' not found
In addition: Warning message:
In data.matrix(data) : NAs introduced by coercion
myname@ip-11-0-0-28:~/rscripts$ 
看起来我的grepl函数有问题。但在Rstudio中运行时,它可以正常工作,只是在从shell调用脚本时不行

但我在基于dplyry动词过滤器的单独脚本中也遇到了其他错误

如果有人认识到这个问题,请帮助!如果需要更多信息,请让我知道,我会补充

另外,我试着在本地shell中运行脚本,结果成功了。这可能是我的Amazon服务器的问题吗?

Shell中的文件:

shell$ r < input.R > output.CSV
我不确定是否在R上工作。
你可以试试

通过反复试验,我发现在每个函数的库名称前面加上前缀解决了这个问题,例如dplyr::select。我不知道为什么,但我希望我能理解。这只需要在从ssh r myscript.r调用脚本时完成。在我测试的所有其他环境中,情况并非如此,包括本地终端、本地RStudio实例、托管RStudio实例-所有这三个环境都不需要我预先编写库,只是在通过ssh调用时,我想,在同事的提示下,这与库路径有关,其中RStudio使用的库路径与通过该服务器上的终端调用r时不同。谢谢你的尝试,但那没有帮助
shell$ r < input.R > output.CSV