Browse files

Moves function to separate file.

  • Loading branch information...
1 parent ff3641e commit 0c26e2758d55238bc148b4cc58cb1ddb9428999d @mollietaylor committed Oct 28, 2013
Showing with 19,727 additions and 40 deletions.
  1. +19,684 −0 allTracks.csv
  2. +41 −0 functions.R
  3. +2 −40 import.R
View
19,684 allTracks.csv
19,684 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
41 functions.R
@@ -0,0 +1,41 @@
+appendTrack <- function(fileNumbers) {
+ for (fileNumber in fileNumbers) {
+
+ newFilename <- paste(sub(paste("\\.", extension, sep = ""), "", gpxFilenames[fileNumber]), ".csv", sep = "") # deletes original extension
+
+ gpsbabelCommand <- paste("sudo gpsbabel -t -i ",
+ GPSType,
+ " -f '",
+ gpxFilenames[fileNumber],
+ "' -o unicsv -F '",
+ newFilename,
+ "'",
+ sep = "")
+
+ system(gpsbabelCommand)
+
+ # add variables (based on GPS/addvariables.R)
+ track <- read.csv(newFilename,
+ header = TRUE)
+ if(!exists("Altitude", track))
+ (track$Altitude <- NA)
+ if(!exists("Date", track))
+ (track$Date <- NA)
+ if(!exists("Time", track))
+ (track$Time <- NA)
+ track <- track[c("Latitude", "Longitude", "Altitude", "Date", "Time")]
+ track$Seg <- 1
+ track$Seg[1] <- NA # keeps map from drawing a line between one ride and the next
+
+ # need code to check whether it should append or not
+
+ write.table(track,
+ "allTracks.csv",
+ append = TRUE,
+ quote = FALSE,
+ sep = ",",
+ row.names = FALSE,
+ col.names = FALSE)
+
+ }
+}
View
42 import.R
@@ -5,11 +5,11 @@
# All rights reserved
#
-
# system() # intern = TRUE?
# file1 <- read.csv(file.choose(),
# header = TRUE)
+
extension <- readline("What extension do your files have? (Options: gpx, kml, csv)\n")
# extension <- ".gpx"
extension <- sub("\\.", "", extension) # cuts the period, so they're standardized
@@ -25,42 +25,4 @@ gpxFilenames <- Sys.glob(paste("Imported Files/*.", extension, sep = ""))
fileNumbers <- 1:length(gpxFilenames)
-for (fileNumber in fileNumbers) {
-
- newFilename <- paste(sub(paste("\\.", extension, sep = ""), "", gpxFilenames[fileNumber]), ".csv", sep = "") # deletes original extension
-
- gpsbabelCommand <- paste("sudo gpsbabel -t -i ",
- GPSType,
- " -f '",
- gpxFilenames[fileNumber],
- "' -o unicsv -F '",
- newFilename,
- "'",
- sep = "")
-
- system(gpsbabelCommand)
-
- # add variables (based on GPS/addvariables.R)
- track <- read.csv(newFilename,
- header = TRUE)
- if(!exists("Altitude", track))
- (track$Altitude <- NA)
- if(!exists("Date", track))
- (track$Date <- NA)
- if(!exists("Time", track))
- (track$Time <- NA)
- track <- track[c("Latitude", "Longitude", "Altitude", "Date", "Time")]
- track$Seg <- 1
- track$Seg[1] <- NA # keeps map from drawing a line between one ride and the next
-
-# need code to check whether it should append or not
-
- write.table(track,
- "allTracks.csv",
- append = TRUE,
- quote = FALSE,
- sep = ",",
- row.names = FALSE,
- col.names = FALSE)
-
-}
+appendTrack(fileNumbers)

0 comments on commit 0c26e27

Please sign in to comment.