等到 R 在集群上执行时加载一个对象

Wait till R loads an object while executing on the cluster

我正在 Rivanna (SLURM) 集群上执行 RScript。当它尝试访问我使用 load() 命令加载的对象时失败。当我以交互方式使用 RStudio 时它工作正常,但是当我将脚本作为 sbatch 作业任务提交给 运行 时失败并出现错误:

Error in 1:nrow(UMI_count) : argument of length 0 Execution halted

我想,有一些特定的命令可以指示集群等待对象加载,那么它们是什么?

我在这里添加了代码,当我第一次 运行 它时失败了,但是当 UMI_count 矩阵加载时,第二个 运行 以某种方式工作:

# For libraries installation
source("https://bioconductor.org/biocLite.R")

name_of_file <- "GSM2599701_Gene.count.matrix.celegans.cell.Rdata"

path_to_file <- paste0("/home/nikita/Desktop/CElegans_raw_data/",
name_of_file, sep="")
load(path_to_file, verbose=TRUE)

# Removing genes with 0 - counts in all of the columns
num_removed = 0
for(i in 1:nrow(UMI_count)) {
  idx = i - num_removed
...
...

问题是由于 R 尝试加载所需的包 Matrix 并在它发生之前执行 nrow(UMI_count) 引起的。添加以下代码解决了这个问题:

if("Matrix" %in% rownames(installed.packages()) == FALSE) 
{
  install.packages("Matrix")
}
library(Matrix)

...