Pranav Pandya Pranav Pandya - 1 year ago 773
R Question

Error in file(file, "rt") : invalid 'description' argument in complete.cases program

I am writing an R function that reads a directory full of files and reports the number of completely observed cases in each data file. The function returns a data frame where the first column is the name of the file and the second column is the number of complete cases.

such as,

id nobs
1 108
2 345

Here is the function I wrote:

complete <- function(directory, id = 1:332) {

for(i in 1:332) {


I execute the function:


but I'm getting this error:

Error in file(file, "rt") : invalid 'description' argument

I also tried the
function to debug my code and it gives this output:

# 4: file(file, "rt") at #6
# 3: read.table(file = file, header = header, sep = sep, quote = quote,
# dec = dec, fill = fill, comment.char = comment.char, ...) at #6
# 2: read.csv(path) at #6
# 1: complete("specdata", id = 1:332)

Answer Source

It's hard to tell without a completely reproducible example, but I suspect your problem is this line:


id here is a vector, so path becomes a vector of character strings, and when you call read.csv you're passing it all the paths at once instead of just one. Try changing the above line to


and see if that works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download