Rcript Error in if (nx >= 2^31 || ny >= 2^31) stop(“long vectors are not supported”)

孤人 提交于 2021-02-11 12:32:10

问题


UPD: replaced merge to inner_join, new error:

Error in UseMethod("tbl_vars") :
  no applicable method for 'tbl_vars' applied to an object of class "function"
Calls: inner_join ... tbl_vars -> new_sel_vars -> structure -> tbl_vars_dispatch

I am trying to run my R-script from command line, but it is return error:

Error in if (nx >= 2^31 || ny >= 2^31) stop("long vectors are not supported") :
  missing value where TRUE/FALSE needed
Calls: merge -> merge.data.frame
Execution halted

What it's mean?

Where are no one problems, when I run similar code from R or Rstudio. How can I fix this issue?

Part of R-script

clonotypes_tables = function(name, cell, mode){
  sub = subset(metadata, metadata$donor == as.character(name))
  sub =  subset(sub, sub$cell_type == as.character(cell))
  if (nrow(sub) > 1){
    sub = sub[order(sub$time_point), ]
  
    if (file.exists(paste(getwd(), sub$file_name[1], sep="/")) & file.exists(paste(getwd(), sub$file_name[2], sep="/"))){
      point1 = read.table(sub$file_name[1], header = T)
      #cat("check1")
      point2 = read.table(sub$file_name[2], header = T)
      
    
      if (nrow(point1) >= 1000 & nrow(point2) >= 1000){
        #common.clonotype = merge(point1[1:1000,], point2[1:1000,], by = c("cdr3aa", "v"))
        if (mode == "CDR3_V"){
          common.clonotype = merge(point1, point2, by = c("cdr3aa", "v"))
          common.clonotype$clon = paste(common.clonotype$cdr3aa, common.clonotype$v, sep = "~")
        }
        else{
          common.clonotype = merge(point1, point2, by = c("cdr3aa"))
          common.clonotype$clon = common.clonotype$cdr3aa
        }
        common.clonotype = common.clonotype[,c("clon", "freq.x", "freq.y")]
        colnames(common.clonotype) = c("Clonotypes", "0.5", "1")
        dim(common.clonotype)
        common.clonotype = common.clonotype[order(common.clonotype[2], decreasing = T), ]
        common.clonotype
      }
      #return(common.clonotype)
    }
  else{
    print(paste(name, cell, "hasn't two time points", sep = " ")) 
   }
  }
}

回答1:


I guess you ran your R-script from command line on larger files or different files. The built-in (base) merge function won't merge data frames with more than 2^31 rows. Check the merge.data.frame code:

...
nx <- nrow(x <- as.data.frame(x))
ny <- nrow(y <- as.data.frame(y))
if (nx >= 2^31 || ny >= 2^31) 
    stop("long vectors are not supported")
...

Try alternative merge functions such as ..._join in dplyr library or the most efficient data.table framework.



来源:https://stackoverflow.com/questions/65888946/rcript-error-in-if-nx-231-ny-231-stoplong-vectors-are-not-support

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!