Reputation: 367
I'm new to R studio and was not well aware of this portal T&C, so was blocked for questing for 5 days. I have a code for importing multiple files from any directory to R. Using this code for doing so, but the problem is this code runs sometime and sometime it gets failed with mentioned error. I tried to found the solution of this but yet not found any solution.
library(data.table)
t = setwd("/home/dp/vishan/olp_data/19164/1/")
files <- file.info(list.files(path = t,pattern = "", full.names=TRUE))
files = rownames(files)[files$size > 0]
temp <- lapply(files, fread, sep=",")
Error:
Error in FUN(X[[i]], ...) :
'input' can not be a directory name, but must be a single character string containing a file name, a command, full path to a file, a URL starting 'http[s]://', 'ftp[s]://' or 'file://', or the input data itself.
Thanks in advance!
Upvotes: 0
Views: 45
Reputation: 11762
try using
files <- file.info(list.files(path = t,pattern = "", full.names=TRUE))
files <- subset(files, !isdir & size > 0)
temp <- lapply(rownames(files), fread, sep=',')
since list.files
also shows directories. The data.frame you create in files
can be easily subset on the isdir
column which indicates if this is a directory or a file.
Upvotes: 1