R Sys.setenv
来源:互联网 发布:seo帝国管理系统 编辑:程序博客网 时间:2024/06/06 02:21
http://stackoverflow.com/questions/17583846/failed-to-remotely-execute-r-script-which-loads-library-rhdfs
Failed to remotely execute R script which loads library “rhdfs”
I'm working on a project using R-Hadoop, and got this problem.
I'm using JSch in JAVA to ssh to remote hadoop pseudo-cluster, and here are part of Java code to create connection.
/* Create a connection instance */Connection conn = new Connection(hostname);/* Now connect */conn.connect();/* Authenticate */boolean isAuthenticated = conn.authenticateWithPassword(username, password);if (isAuthenticated == false)throw new IOException("Authentication failed.");/* Create a session */Session sess = conn.openSession();//sess.execCommand("uname -a && date && uptime && who");sess.execCommand("Rscript -e 'args1 <- \"Dell\"; args2 <- 1; source(\"/usr/local/R/mytest.R\")'");//sess.execCommand("ls");sess.waitForCondition(ChannelCondition.TIMEOUT, 50);
I tried several simple R scripts, and my codes worked fine. But when it comes to R-Hadoop, the R script will stop running. But if I runRscript -e 'args1 <- "Dell"; args2 <- 1; source("/usr/local/R/mytest.R")'
directly in remote server, everything works fine.
Here is what I got after taking Hong Ooi's suggestion:Instead of using Rscript, I used following command:
sess.execCommand("R CMD BATCH --no-save --no-restore '--args args1=\"Dell\" args2=1' /usr/local/R/mytest.R /usr/local/R/whathappened.txt");
And in the whathappened.txt, I got following error:
> args=(commandArgs(TRUE))> for(i in 1:length(args)){+ eval(parse(text=args[[i]]))+ }> source("/usr/local/R/main.R")> main(args1,args2)Loading required package: rJavaError : .onLoad failed in loadNamespace() for 'rhdfs', details: call: fun(libname, pkgname) error: Environment variable HADOOP_CMD must be set before loading package rhdfsError: package/namespace load failed for 鈥榬hdfs鈥?Execution halted
Well, now the problem is much clearer. Unfortunately, I'm pretty new to linux, and have no idea how to solve this.
2 Answers
Well, I solved this problem like this:
sess.execCommand("source /etc/profile; R CMD BATCH --no-save --no-restore '--args args1=\"Dell\" args2=1' /usr/local/R/mytest.R /usr/local/R/whathappened.txt");
The problem was caused by environment. SSH to the remote Hadoop cluster actually uses a different environment, so variables like $HADOOP_CMD will not be discovered. There are multiple ways to let the SSH session know how to pick the environment variables.
In my method, the "source /etc/profile"
can tell the sshed environment where to find the environment virables.
Well, I just found another solution by myself:
Instead of caring about env from outside Hadoop cluster, can set env in R scripts like:
Sys.setenv(HADOOP_HOME="put your HADOOP_HOME path here")Sys.setenv(HADOOP_CMD="put your HADOOP_CMD path here")library(rmr2)library(rhdfs)
- R Sys.setenv
- setenv
- setenv()
- R语言:Sys.sleep()与Sys.time()
- set setenv
- setenv getenv
- setenv setfenv
- bin\setenv.bat,bin/setenv.sh
- sys
- /sys
- sys
- sys
- setenv怎么用
- Emacs Eshell 命令 setenv
- getenv,putenv,setenv函数
- setenv,getenv,fork
- No command 'setenv' found
- getenv、setenv函数
- MFC重绘
- 为什么QQ在线状态成灰色“未启用”状态?
- 随感
- android消息推送demo
- 聊天室html页面提交内容后div内容自动滚到底部
- R Sys.setenv
- 微街谈商业中的蝴蝶效应
- adb server is out of date
- Struts2路径和中文问题
- 中国游戏机禁令解除有助文化产业升级
- Android读取服务端TXT(JSON格式数据)返回汉字乱码的问题
- U盘安装红帽,rhel镜像制作
- IOS--判断设备大小和版本
- iOS项目的目录结构和开发流程
sink
to redirect output to a file. That might help you diagnose what's going on.–Hong OoiJul 11 '13 at 17:05