1. For a large number of variables (or large in size e.g. a few MB)
rhsave(n1,n2,n3, file="/path-on-hdfs/data.Rdata")
map.setup = expression({
load("data.Rdata") # no need to give full path
})
rhmr(...,setup=list(map=map.setup),
shared.files=c("/path-on-hdfs/data.Rdata"),....
2. Serialize as strings and pass via mapred
mapred=list()
mapred$c1 = rawToChar(serialize(c1,NULL,ascii=TRUE))
mapred$c2 = rawToChar(serialize(c2,NULL,ascii=TRUE))
map.setup = expression({
c1 = unserialize( charToRaw( Sys.getenv("c1") ))
c2 = unserialize( charToRaw( Sys.getenv("c2") ))
})
rhmr(,.., mapred=mapred,setup=list(map=map.setup))
3. Modify R code using bquote (you should be comfortable with
modifying code at run time)
map = as.expression(bquote({
c1 <- .(c1)
c2 <- .(c2)
.....}, list(c1=c1,c2=c2)))
rhmr(map=map,...)
Note, this code is parsed and modified before being sent to Hadoop. c1
and c2 are hardcoded into the source. Try this
c1=matrix(runif(10),ncol=2)
c2=matrix(runif(10),ncol=2)
map = as.expression(bquote({
c1 <- .(c1)
c2 <- .(c2)
}, list(c1=c1,c2=c2)))
and type map, you'll see c1 and c2 in the source. Use this for i)
small number of global variables ii) small sized variables (< MB)
Regards
Saptarshi
1. If you use rhex(z) and call the script using source, you wont see
errors. The error code is because there
were hadoop/R errors. The errors are printed out by hadoop and using
source will hide these. If you use rhex(z)
then either
a) run rhex(z) interactively at the prompt
b) if you call it via source, then go to the jobtracker and look for the errors
2. You can also try this (either using source or interactively)
j <- rhex(z, async=TRUE)
jr <- rhstatus(j, mon.sec=5,autokill=TRUE)
the last line monitors the job and will kill it if there are R errors
(but will /not/ kill it if there are Hadoop errors, since Hadoop
errors need not be fatal)
Also, it has attributes that contain the R / Hadoop errors.