Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.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
运行代码块时RStudio中的奇怪行为_R_Rstudio - Fatal编程技术网

运行代码块时RStudio中的奇怪行为

运行代码块时RStudio中的奇怪行为,r,rstudio,R,Rstudio,更新:我也在RStudio IDE论坛上发布了这篇文章。RStudio团队复制了该漏洞并提交了一份漏洞报告。如果我从RStudio团队那里听到更多关于这个问题的消息,我会再次更新 我在RStudio中遇到了一个奇怪的行为,我在Ubuntu16.04 LTS的版本0.99.903和1.0.143中发现了这个行为,尽管我还没有测试过早期版本或其他操作系统。在Linux命令行上运行时,在R中不会出现这种情况。基本上,如果一个自定义函数在同一代码块中运行两次,第二次运行时,对dir()的第一次调用可以正

更新:我也在RStudio IDE论坛上发布了这篇文章。RStudio团队复制了该漏洞并提交了一份漏洞报告。如果我从RStudio团队那里听到更多关于这个问题的消息,我会再次更新

我在RStudio中遇到了一个奇怪的行为,我在Ubuntu16.04 LTS的版本0.99.903和1.0.143中发现了这个行为,尽管我还没有测试过早期版本或其他操作系统。在Linux命令行上运行时,在R中不会出现这种情况。基本上,如果一个自定义函数在同一代码块中运行两次,第二次运行时,对dir()的第一次调用可以正常工作,但第二次调用不能正常工作,而是只返回NAs。它发生在一种奇怪的条件组合中,包括以下情况:

1) 该函数调用“dir()”或“list.files()”两次

2) 正在读取的目录包含大约3100多个文件

3) 该函数包括对“plot()”的调用

4) 在同一代码块中调用该函数两次

我在下面包含了一个可复制的示例。如果能帮助我确定为什么会发生这种情况以及如何避免,我将不胜感激。请记住,如果您运行代码并希望重新运行它,则需要删除在第一步中创建的目录,或者至少删除其中的文件,以便重现有问题的行为。谢谢

# Create a directory
dir.create(path = "~/test.2017-06-06")

# Define function.  This reads the files in the directory
# twice, each time storing the result in a different vector.
# Then it prints the length of each vector and the first 
# 3 files in them. 
Function = function() {
  fileNames1 = dir(path = "~/test.2017-06-06",  
                   full.names = T)
  fileNames2 = dir(path = "~/test.2017-06-06", 
                   full.names = T)
  cat("length(fileNames1):", length(fileNames1), ",", fileNames1[1:3], "\n")
  cat("length(fileNames2):", length(fileNames2), ",", fileNames2[1:3], "\n")
  plot(1)
}

# Write 3100 files containing NULL to the new directory
fileNames = paste0("~/test.2017-06-06/file", 1:3100, ".txt")
for(i in fileNames) write(x = NULL, file = i)

# Call the function twice (this works)
Function()
Function()

# Write 3200 files to the directory 
fileNames = paste0("~/test.2017-06-06/file", 1:3200, ".txt")
for(i in fileNames) write(x = NULL, file = i)

# Call the function twice again (this doesn't work)
Function()
Function()