I am trying to run this script as a loop function as I have over 200 files in a folder and I am trying to produce one CSV file at the end listing all of the data that I need to extract.
I have tried various ways of running this in a loop e.g. In R, how to extracting two values from XML file, looping over 5603 files and write to table
Whenever I do try these different options I get errors like:
Error: XML content does not seem to be XML or permission denied.
However, when I run the code selecting just one file it runs fine. These errors only seems to occur when I try convert it into a loop function for multiple files in a single folder.
Here is the original code used for a single file:
doc<-xmlParse("//file/path/32460004.xml")
xmldf <- xmlToDataFrame(nodes = getNodeSet(doc, "//BatRecord"))
df1 <- data.frame(xmldf)
df1 <- separate(df1, xmldf.DateTime, into = c("Date", "Time"), sep = " ")
df1$Lat <- substr(xmldf$GPS,4,12)
df1$Long <- substr(xmldf$GPS,13,25)
df_final <- data.frame(df1$xmldf.Filename, df1$Date, df1$Time, df1$xmldf.Duration, df1$xmldf.Temperature, df1$Lat, df1$Long)
colnames(df_final) <- c("Filename", "Date", "Time", "Call Duration", "Temperature", "Lat", "Long")
write.csv(df_final, "//file/path/test_file.csv")
Here is a link to some example files:
https://drive.google.com/drive/folders/1ZvmOEWhzlWHRl2GxZrbYY9y7YSZ5j9Fj?usp=sharing
Any help is appreciated.
Here is my version details:
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 6.3
year 2020
month 02
day 29
svn rev 77875
language R
version.string R version 3.6.3 (2020-02-29)
nickname Holding the Windsock