-1

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 = " ")) 
   }
  }
}
  • Welcome to SO, Elya Shnayder! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically after `set.seed(1)`), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Jan 25 '21 at 17:29
  • 1
    Hi Elya. Welcome to S.O! I've suggested an edit to your question to remove your 'Update' edit. If you are facing a new problem, please create a new question. Combining multiple questions in one thread will create something unhelpful, confusing, and impossible to reliably answer. – Captain Hat Jan 26 '21 at 00:41

1 Answers1

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.

Regis
  • 148
  • 1
  • 6
  • 1
    The problem *can* be the resulting size of the merged frames, common if the columns to join effectively produce a cartesian join (I've seen that with floating-point join fields, which should never be relied on). In this case, though, the `nx` and `ny` are hints to the [source code](https://github.com/wch/r-source/blob/8d5571f71ed163e85e3e1035a1f9b787197fea05/src/library/base/R/merge.R#L60-L61) which suggest that the problem is in either the first or second frame, before any joining can be attempted. – r2evans Jan 25 '21 at 19:07
  • 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 – Elya Shnayder Jan 25 '21 at 20:59