bmewing / gpx

@@ -1,6 +1,6 @@
Loading
1 1
#' @export
2 2
3 -
read_gpx = function(file){
3 +
read_gpx = function(file) {
4 4
  #' @title Read a .gpx file into a data.frame
5 5
  #'
6 6
  #' @description Read a .gpx file into a list of data.frames
@@ -16,11 +16,11 @@
Loading
16 16
  #' hikes$routes
17 17
  #' }
18 18
19 -
  if(!file.exists(file)) stop("Specified file does not exist")
19 +
  if (!file.exists(file)) stop("Specified file does not exist")
20 20
  data = xml2::read_html(file)
21 21
  routes = extract_routes(data)
22 22
  tracks = extract_tracks(data)
23 23
  output = list(routes = routes
24 -
               ,tracks = tracks)
24 +
              , tracks = tracks)
25 25
  return(output)
26 26
}

@@ -1,60 +1,77 @@
Loading
1 -
extract_tracks = function(data){
2 -
  tracks = rvest::html_nodes(data,"trk")
3 -
  segments = lapply(tracks,rvest::html_nodes,"trkseg")
4 -
  points = lapply(segments,rvest::html_nodes,"trkpt")
5 -
  output = lapply(points,process_points)
6 -
  output = lapply(seq_along(output),function(i){output[[i]][["Segment ID"]] = i;return(output[[i]])})
1 +
extract_tracks = function(data) {
2 +
  tracks = rvest::html_nodes(data, "trk")
3 +
  segments = lapply(tracks, rvest::html_nodes, "trkseg")
4 +
  points = lapply(segments, rvest::html_nodes, "trkpt")
5 +
  if (length(points) == 0) {
6 +
    output = generate_empty()
7 +
  } else {
8 +
    output = lapply(points, process_points)
9 +
    output = lapply(seq_along(output), function(i){output[[i]][["Segment ID"]] = i;return(output[[i]])}) #nolint
10 +
  }
7 11
  return(output)
8 12
}
9 13
10 -
extract_routes = function(data){
11 -
  routes = rvest::html_nodes(data,"rte")
12 -
  points = lapply(routes,rvest::html_nodes,"rtept")
13 -
  output = lapply(points,process_points)
14 +
extract_routes = function(data) {
15 +
  routes = rvest::html_nodes(data, "rte")
16 +
  points = lapply(routes, rvest::html_nodes, "rtept")
17 +
  if (length(points) == 0) {
18 +
    output = generate_empty()
19 +
  } else {
20 +
    output = lapply(points, process_points)
21 +
  }
14 22
  return(output)
15 23
}
16 24
17 -
process_points = function(points){
25 +
generate_empty = function() {
26 +
  empty = data.frame("Elevation" = logical()
27 +
                   , "Time" = logical()
28 +
                   , "Latitude" = logical()
29 +
                   , "Longitude" = logical()
30 +
                   , stringsAsFactors = FALSE)
31 +
  return(list(empty))
32 +
}
33 +
34 +
process_points = function(points) {
18 35
  attrs = rvest::html_attrs(points)
19 -
  df = do.call(rbind,attrs)
20 -
  ele = as.numeric(extract_feature(points,"ele"))
21 -
  time = lubridate::as_datetime(extract_feature(points,"time"))
22 -
  lat = as.numeric(extract_feature(points,"lat"))
23 -
  lon = as.numeric(extract_feature(points,"lon"))
36 +
  df = do.call(rbind, attrs)
37 +
  ele = as.numeric(extract_feature(points, "ele"))
38 +
  time = lubridate::as_datetime(extract_feature(points, "time"))
39 +
  lat = as.numeric(extract_feature(points, "lat"))
40 +
  lon = as.numeric(extract_feature(points, "lon"))
24 41
  output = data.frame("Elevation" = ele
25 -
                      ,"Time" = time
26 -
                      ,"Latitude" = lat
27 -
                      ,"Longitude" = lon
28 -
                      ,stringsAsFactors = FALSE)
42 +
                     , "Time" = time
43 +
                     , "Latitude" = lat
44 +
                     , "Longitude" = lon
45 +
                     , stringsAsFactors = FALSE)
29 46
  extensions = extract_extensions(points)
30 -
  output = cbind(output,extensions)
47 +
  output = cbind(output, extensions)
31 48
  return(output)
32 49
}
33 50
34 -
extract_feature = function(points,feature){
35 -
  attr = rvest::html_attr(points,feature)
36 -
  node = rvest::html_text(rvest::html_node(points,feature))
37 -
  output = coalesce(attr,node)
51 +
extract_feature = function(points, feature) {
52 +
  attr = rvest::html_attr(points, feature)
53 +
  node = rvest::html_text(rvest::html_node(points, feature))
54 +
  output = coalesce(attr, node)
38 55
  return(output)
39 56
}
40 57
41 -
extract_extensions = function(points){
42 -
  extensions = rvest::html_nodes(points,"extensions")
58 +
extract_extensions = function(points) {
59 +
  extensions = rvest::html_nodes(points, "extensions")
43 60
  if (length(extensions) == 0) {
44 61
    output = rep(NA, length(points))
45 62
  } else {
46 63
    children = rvest::html_children(extensions)
47 64
    output = xml2::as_list(children)
48 -
    output = lapply(output,unlist)
49 -
    output = do.call(rbind,output)
65 +
    output = lapply(output, unlist)
66 +
    output = do.call(rbind, output)
50 67
  }
51 68
  return(output)
52 69
}
53 70
54 -
coalesce <- function(...) {
71 +
coalesce = function(...) {
55 72
  Reduce(function(x, y) {
56 -
    i <- which(is.na(x))
57 -
    x[i] <- y[i]
73 +
    i = which(is.na(x))
74 +
    x[i] = y[i]
58 75
    x},
59 76
    list(...))
60 77
}
Files Coverage
R 100.00%
Project Totals (2 files) 100.00%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading