小编Lud*_*aux的帖子

Rscript无法找到功能

我需要通过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)

你知道问题的来源以及如何解决吗?

r rscript

14
推荐指数
1
解决办法
4391
查看次数

优化版本的grep匹配矢量与矢量

假设我有两个字符向量,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,以便找到的每个值的匹配函数ab.我当然可以这样做:

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)

regex optimization grep r vector

7
推荐指数
2
解决办法
573
查看次数

标签 统计

r ×2

grep ×1

optimization ×1

regex ×1

rscript ×1

vector ×1