我需要通过bash shell运行几个脚本,Rscript并且我使用的一些函数需要该函数isGeneric.但是,在这种情况下,流程就像那样(例如):
Error in .getLogLik() : could not
find function "isGeneric"
Calls: main -> dredge -> .getLik -> .getLogLik
Execution halted
Run Code Online (Sandbox Code Playgroud)
这可以如下再现
# in the bash shell
echo "isGeneric('apply')" > /tmp/test.R
Rscript /tmp/test.R
Run Code Online (Sandbox Code Playgroud)
结果:
Error: could not find function "isGeneric"
Execution halted
Run Code Online (Sandbox Code Playgroud)
但是,如果我们打开一个R会话并键入以下内容,它的工作原理如下:
# in the R shell
isGeneric('apply')
[1] FALSE
Run Code Online (Sandbox Code Playgroud)
你知道问题的来源以及如何解决吗?
假设我有两个字符向量,a并且b:
set.seed(123)
categ <- c("Control", "Gr", "Or", "PMT", "P450")
genes <- paste(categ, rep(1:40, each=length(categ)), sep="_")
a0 <- paste(genes, "_", rep(1:50, each=length(genes)), "_", sep="")
b0 <- paste (a0, "1", sep="")
ite <- 200
lg <- 2000
b <- b0[1:lg]
a <- (a0[1:lg])[sample(seq(lg), ite)]
Run Code Online (Sandbox Code Playgroud)
我想申请的grep,以便找到的每个值的匹配函数a中b.我当然可以这样做:
sapply(a, grep, b)
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有更高效的东西,因为我必须在模拟中为更大的向量运行这么多次(请注意,我不想mclapply使用它,因为我已经使用它来运行我的模拟的每次迭代) :
system.time(lapply(seq(100000), function(x) sapply(a, grep, b)))
library(parallel)
system.time(mclapply(seq(100000), function(x) sapply(a, grep, b), mc.cores=8))
Run Code Online (Sandbox Code Playgroud)