Skip to content
Prev 388501 / 398513 Next

error message from read.csv in loop

It seems that your problem is that you are using single quotes inside of
the double quotes. This is not necessary. Here is the corrected for-loop:

for (j in 1:nrow(ora))
{
        mycol  <- ora[j,"fname"]
        mycsv  <- paste0(mycol,".csv")
        rdcsv  <- noquote(paste0("w:/project/_Joe.B/Oracle/data/", mycsv))
        rr     <- read.csv(rdcsv)
}

Also note that the rr variable will only store the last CSV, not all CSV.
You will need to initialize the rr variable as a list to store all CSVs if
that is what you require. Something like this:

# Initialize the rr variable as a list.
rr <- as.list(rep(NA, nrow(ora)))

# Run the for-loop to store all the CSVs in rr.
for (j in 1:nrow(ora))
{
        mycol  <- ora[j,"fname"]
        mycsv  <- paste0(mycol,".csv")
        rdcsv  <- noquote(paste0("w:/project/_Joe.B/Oracle/data/", mycsv))
        rr[[j]]     <- read.csv(rdcsv)
}

Regards
Migdonio G.

On Fri, Jul 9, 2021 at 1:10 PM Kai Yang via R-help <r-help at r-project.org>
wrote: