I am processing all files in a directory and I want to get metadata for filenames, save it in a dataframe, then eventually load the dataframe into a RSQLite table after the directory is processed.
Ref: https://stackoverflow.com/a/51913491/9410024 and maybe https://stackoverflow.com/a/45522323/9410024
I don't understand the warning messages and why the filenames haven't been loaded into the dataframe:
setwd('C://tst//')
df <- data.frame("filename"= character(0), stringsAsFactors=FALSE)
for (fn in Sys.glob("tst*.dat")) {
print(fn)
df[nrow(df) + 1,] = list(fn)
}
Output:
[1] "tst1.dat"
[1] "tst2.dat"
[1] "tst3.dat"
Warning messages:
1: In `[<-.data.frame`(`*tmp*`, nrow(df) + 1, , value = list("tst1.dat")) :
replacement element 1 has 1 row to replace 0 rows
2: In `[<-.data.frame`(`*tmp*`, nrow(df) + 1, , value = list("tst2.dat")) :
replacement element 1 has 1 row to replace 0 rows
3: In `[<-.data.frame`(`*tmp*`, nrow(df) + 1, , value = list("tst3.dat")) :
replacement element 1 has 1 row to replace 0 rows
> dfrun
[1] filename
<0 rows> (or 0-length row.names)
>