You could wrap them up into a function call, but just using lapply will be more straight forward I think. Using the for-loop results in x, temp, and visit.id hanging out afterwords. Using something from the *apply family has the benefit leaving a clean working space behind as well. Out <- lapply(files, function(x) readGPS(i = "gpx", f = x, type = "w"))Īnd out is now a list of 2, where each object is a ame with the name of the file that it was associated with previously. Lapply(files, function(x) file.rename(from = x, to = gsub("\\s ", "_", x))) Replace with the character of your choice. #Replace all space characters with a "_". For example, files <- dir(pattern = "\\.gpx") Im sure Robert will chime in, but let me point out the latest version of GPSBabel has read and write support of Lowrance USR for waypoints, tracks, and routes. I find dealing with a list object easier than having lots of different objects floating around. Utility I mentioned has full support for. Have you tried this on a fresh instance of R?įWIW, I would probably read all of these files into a single list object. Is that right? I assume the NA bit in the file names is due to how you are defining visit.id and my test file names not fitting into that paradigm. So, if you create a device type with the download command gpsbabel type-i garmin-o gpx in out (this is actually the download command for the predefined device type ‘Garmin serial’) and then use it to download waypoints from port /dev/ttyS0 to the file output.gpx, QGIS will replace the keywords and run the command gpsbabel-w-i garmin-o. I have two objects names test1.gpx_NA_NA and test2.gpx_NA_NA with three observations of 28 variables. NOTE: To run readGPS you will need the open source GPSBabel program installed and referenced in your PATH variable.Īfter installing GPSBabel and updating the PATH variable, your code snippet ran fine. I can read one file thus: library(maptools) I want to load them into R with different names and manipulate them. gpx files (these contain GPX waypoint data from a Garmin eTrex).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |