本文介绍了R 包 rJava 仅在我使用 sudo 启动 R 时加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Ubuntu 14.04.1 上运行 R 3.0.2.我已经安装了 rJava 包,但是如果我使用 sudo 启动它,我只能让它在 R/RStudio 中工作.如果我单击应用程序启动器,或者只是在命令行中输入 R,则在加载 rJava 库时会出现以下错误:

I'm running R 3.0.2 on Ubuntu 14.04.1. I've installed the rJava package, but I can only get it to work in R/RStudio if I launch it with sudo. If I click on the application launcher, or just enter R in the command line, I get the following error when loading the rJava library:

> library(rJava)
Error : .onLoad failed in loadNamespace() for 'rJava', details:
    call: dyn.load(file, DLLpath = DLLpath, ...)
    error: unable to load shared object '/usr/lib/R/site-library/rJava/libs/rJava.so':
    libjvm.so: cannot open shared object file: No such file or director
Error: package or namespace load failed for ‘rJava’

但是,如果我在终端中输入sudo rstudio"或sudo R",则 rJava 加载没有问题.有人知道我做错了什么吗?

However, if I type 'sudo rstudio' or 'sudo R' in a terminal, rJava loads without a problem. Does anybody know what I'm doing wrong?

可能相关的问题:我通过输入

Possibly related issue: I installed rJava by entering

sudo apt-get install r-cran-rjava

在命令提示符下;正常安装:

at the command prompt; installing the normal way:

apt-get install r-cran-rjava

对我不起作用,从 R 中安装也不起作用(不使用 sudo 启动它).当我尝试以这种方式安装时,我遇到了与 这个问题.

did not work for me, and neither did installing from within R (without launching it using sudo). When I tried to install this way, I ran into the same problem as addressed in this question.

推荐答案

/usr/lib/R/site-library/rJava/libs/rJava.so 文件可能无法被任何人读取非root用户.您可以通过以下方式检查:

The file /usr/lib/R/site-library/rJava/libs/rJava.so is probably not readable by any user other than root. You can check that with:

ls -l /usr/lib/R/site-library/rJava/libs/rJava.so

如果输出是 rw-------rw-rw---- 那么简单的用户将无法阅读它.您可以使用 chmod 命令更正:

If the output is rw------- or rw-rw---- then simple users won't be able to read it. You can correct that with the chmod command:

chmod -R a+rX /usr/lib/R/site-library/rJava/

这篇关于R 包 rJava 仅在我使用 sudo 启动 R 时加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 05:28