What is producing the error "Argument 2 must have names"

Hello,

This below is 1) the result of running the code,
Error in cbind_all(x) : Argument 2 must have names
Called from: cbind_all(x)
Browse[1]> > print(class(dataList)) [1] "data.frame" > print(class(new_filenames)) [1] "data.frame"

  1. and the reprex of the code I am writing now.
    How can I attach the files? Should I copy and paste them?

thanks

library(data.table)   # for fread() and rbindlist()
library(magrittr)   # use piping for clarity
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:data.table':
#> 
#>     between, first, last
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(reprex)
# file directorylists
list1 <- list(a = "JF_160426_Dep2Plas_tryp_Gpep_SIDtarg-(06)_PSMs.txt", b = "JF_160426_Dep2Plas_ctryp_Gpep_SIDtargFULL_PSMs.txt",
                         c = "160824_JF_udep_tryp_Hi_SIDdda_FULL_NewParse-(05)_PSMs.txt", d = "150413_JF_GPeps_SIDtarg_GPstdMix_Tryp_2runs_v3_PSMs.txt")
list2 <- list(a = "JF_160426_Dep2Plas_tryp_Gpep_SIDtarg-(06)_PSMs.txt", b = "JF_160426_Dep2Plas_ctryp_Gpep_SIDtargFULL_PSMs.txt",
                            c = "160824_JF_udep_tryp_Hi_SIDdda_FULL_NewParse-(05)_PSMs.txt")
list3 <- list(a = "JF_160426_Dep2Plas_tryp_Gpep_SIDtarg-(06)_PSMs.txt", b = "JF_160426_Dep2Plas_ctryp_Gpep_SIDtargFULL_PSMs.txt")

# file directory list of lists
lc <- list(list1, list2, list3)

#The purpose of the program is to read the files in lc: first list1, second list2 , third list3 and merge the files in each lists separately
#to make 3 sepate files.  The first file will contain the contents of list1, the second file will contents the contents of list2 and the third file
#will contain the contents of list three.

#I am saving the files - 20 lines of each - in the working directory.install

# Length of list
fileListLength <- length(lc)


# These are the names that will be given to the 3 resultng files
new_dataFns <- list("name1", "name2", "name3")
names(new_dataFns)[length(new_dataFns)]<-"new_filenames"
file_dir <- getwd()
dataList = NULL
new_filenames = NULL

lapply(
  lc, 
  function(lc) {
    
    filenames <<- file.path(file_dir, lc)
    new_filenames <<- as.data.frame(file.path(file_dir, new_dataFns))
    lapply(filenames,
           function (filenames) dataList <<- dplyr::bind_rows(read.delim(file=filenames, header=TRUE)))
     lapply(new_filenames,
            function(new_filenames) dataList <<- dplyr::bind_cols(dataList, new_filenames))
    
  }
  
)
#> Warning in file(file, "rt"): cannot open file '/tmp/RtmpzuB1b4/
#> JF_160426_Dep2Plas_tryp_Gpep_SIDtarg-(06)_PSMs.txt': No such file or
#> directory
#> Error in file(file, "rt"): cannot open the connection

print(class(dataList))
#> [1] "NULL"
print(class(new_filenames))
#> [1] "data.frame"

Created on 2018-08-22 by the reprex package (v0.2.0).

1 Like