简体   繁体   English

R中的setwd出错

[英]Error with setwd in R

When trying to use the sample code for SubgraphMining ( the example is on 35th page ), I get an error: 当尝试使用SubgraphMining的示例代码时( 示例在第35页 ),我收到一个错误:

"Error in setwd(paste(Sys.getenv("R_HOME"), "library", "subgraphMining",  : 
  cannot change working directory"

I'm using RStudio 0.97.551, 32-bit R (2.15.3 - this version of R was recommended to use with subgraphMining), igraph0 (was recommeded too, instead of igraph library), Java installed. 我正在使用RStudio 0.97.551,32位R(2.15.3 - 这个版本的R被推荐用于子图形挖掘),igraph0(也被推荐,而不是igraph库),Java安装。 Operation system is Windows 8. Can anyone help me with the issue? 操作系统是Windows 8.任何人都可以帮我解决这个问题吗?

The error message is coming from the gspan function of subgraphMining , from here: 该错误消息从未来gspan的功能subgraphMining ,从这里开始:

setwd(paste(Sys.getenv("R_HOME"), "library", "subgraphMining", 
    "parsemis", sep = "\\"))

The reason for it is that R uses / as path separator, and not \\\\ , which only works on windows. 原因是R使用/作为路径分隔符,而不是\\\\ ,它只适用于Windows。 A workaround is not modify the function and use / instead of \\\\ . 解决方法不是修改函数并使用/而不是\\\\

Btw. 顺便说一句。 this has nothing to do with the igraph package, so I'll remove that tag. 这与igraph包无关,所以我将删除该标签。

In my case, it displayed the error because I expected it to create a new folder which I mentioned in the path in setwd. 在我的情况下,它显示错误,因为我希望它创建一个新的文件夹,我在setwd的路径中提到。 Unfortunately, R does not have this functionality and the matter was resolved when I created the folder and then used setwd command. 不幸的是,R没有这个功能,当我创建文件夹然后使用setwd命令时,问题就解决了。

I know it's almost 1 year since this question was posted. 我知道这个问题发布后差不多1年了。 I encountered the same problem with subgraphMining package. 我遇到了subgraphMining包的同样问题。 A quick hack is: You can write "gspan" on RStudio's command line and it will show the function, copy that function and create your own function in your own script (of course with new name, let's say gspanNew) and fix it by replacing "\\\\" with "/", as Gabor Csardi pointed out. 一个快速的黑客是:您可以在RStudio的命令行上写“gspan”,它将显示该函数,复制该函数并在您自己的脚本中创建您自己的函数(当然使用新名称,比如gspanNew)并通过替换来修复它正如Gabor Csardi指出的那样,“\\\\”和“/”一样。

Cheers! 干杯! :) :)

您始终可以使用file.path(“path”,“with”,“code”)而不是简单粘贴,以使您的代码与操作系统无关。

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

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