Suppose I have several .gpx files (they contain GPX waypoint data from Garmin eTrex). I want to load them into R with different names and manipulate them.
I can read one file this way:
library(maptools)
gpx.raw <- readGPS(i = "gpx", f = "file1_w_12_f_ddf.gpx", type="w")
Suppose I want to read a few of them in memory. I could try the for loop:
files <- list.files(".",pattern = "*.gpx")
for(x in files){
temp <- strsplit(x,"_",fixed=TRUE)
visit.id <- sapply(temp,FUN=function(x){paste(x[1],x[4],substr(x[5],1,3),sep="_")})
assign(visit.id, readGPS(i = "gpx", f = x, type="w"))
}
Running the above program gives the following error:
Error in read.table (con <- textConnection (gpsdata), fill = TRUE, ...): no input lines available. In addition: Warning message: running command 'C: \ PROGRA ~ 2 \ GPSBabel \ gpsbabel.exe - w -i gpx -f file1_w_12_f_ddf.gpx -o tabsep -F - 'has status 1
Please note that I was able to read this file by itself, so it seems that it has nothing to do with the file itself, but with running readGPS in a loop.
, , R , x . , readGPS f = "file1_w_12_f_ddf.gpx": x f = x, f = "x", ? , , GPSBabel...
, .gpx. .
<?xml version="1.0" encoding="UTF-8"?>
<gpx
version="1.0"
creator="GPSBabel - http://www.gpsbabel.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/0"
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
<time>2010-09-14T18:35:43Z</time>
<bounds minlat="18.149888897" minlon="-96.747799935" maxlat="50.982883293" maxlon="121.640266674"/>
<wpt lat="38.855549991" lon="-94.799016668">
<ele>325.049072</ele>
<name>GARMIN</name>
<cmt>GARMIN</cmt>
<desc>GARMIN</desc>
<sym>Flag</sym>
</wpt>
<wpt lat="50.982883293" lon="-1.463899976">
<ele>35.934692</ele>
<name>GRMEUR</name>
<cmt>GRMEUR</cmt>
<desc>GRMEUR</desc>
<sym>Flag</sym>
</wpt>
<wpt lat="25.061783362" lon="121.640266674">
<ele>38.097656</ele>
<name>GRMTWN</name>
<cmt>GRMTWN</cmt>
<desc>GRMTWN</desc>
<sym>Flag</sym>
</wpt>
</gpx>
. readGPS GPSBabel , PATH.