简体   繁体   English

从linux运行r错误:无法打开连接

[英]running r from linux error: cannot open the connection

I have a R file that was created in windows. 我有一个在Windows中创建的R文件。 The file has below code 该文件具有以下代码

print(5+7)
fileConn<-file("ch7.txt","w+")
close(fileConn)

The code works fine in windows R. But I get an error when i try to run that file from Linux. 该代码在Windows R中工作正常。但是,当我尝试从Linux运行该文件时出现错误。 I have R running on my Linux machine and I typed below command. 我在Linux机器上运行了R,并在下面输入了命令。

> source('R_linux.R')
[1] 12
Error in file("ch7.txt", "w+") : cannot open the connection
In addition: Warning message:
In file("ch7.txt", "w+") : cannot open file 'ch7.txt': Permission denied

File permissions are treated differently in linux than they are in windows. 在Linux和Windows中,文件权限的处理方式有所不同。 I would check that you have read/write access to the file in your linux env. 我会检查您是否对Linux环境中的文件具有读/写访问权限。

If your linux has a GUI right click and adjust the permissions. 如果您的Linux具有GUI,请右键单击并调整权限。 If you need to do it in the command line try: 如果需要在命令行中尝试,请尝试:

chmod 664 ch7.txt 

This will give you read and write access at the user and group levels and read access at the 'other' levels. 这将为您提供用户和组级别的读写访问权限,以及“其他”级别的读访问权限。 If you're not too worried about locking down the file you could do: 如果您不太担心锁定文件,可以执行以下操作:

chmod 777 ch7.txt

This will give you read/write/execute permissions at user/group/other levels. 这将为您提供用户/组/其他级别的读取/写入/执行权限。

Further to this double check that the path is correct. 进一步仔细检查路径是否正确。 Your working directory may be slightly different by default from machine to machine. 默认情况下,计算机之间的工作目录可能会略有不同。

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

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