{"id":6688,"date":"2022-08-07T18:19:08","date_gmt":"2022-08-07T18:19:08","guid":{"rendered":"https:\/\/www.garysieling.com\/blog\/?p=6688"},"modified":"2022-08-07T18:20:22","modified_gmt":"2022-08-07T18:20:22","slug":"r-read-garmin-activity-export-summary-to-a-dataframe","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/r-read-garmin-activity-export-summary-to-a-dataframe\/","title":{"rendered":"R: Read Garmin activity export summary to a dataframe"},"content":{"rendered":"\n<p>The Garmin export is a deeply nested JSON structure. It only appears to fill in columns where there is data. Like so:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  {\n    \"summarizedActivitiesExport\": &#91;\n      {\n        \"activityId\": 9342780544,\n        \"uuidMsb\": -8608655323230679000,\n        \"uuidLsb\": -8443901297724183000,\n        \"name\": \"Ambler Running\",\n        \"activityType\": \"running\",\n        \"userProfileId\": 106383175,\n        \"timeZoneId\": 149,\n        \"beginTimestamp\": 1659703707000,\n        \"eventTypeId\": 9,\n        ...<\/code><\/pre>\n\n\n\n<p>The following code will read it to a dataframe:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df &lt;- data.table::rbindlist(read_json(filename)&#91;&#91;1]]$summarizedActivitiesExport, fill=TRUE) <\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>df<br>activityId uuidMsb uuidLsb name activityType userProfileId timeZoneId beginTimestamp eventTypeId rule<br>1: 9342780544 -8.608655e+18 -8.443901e+18 Ambler Running running 106383175 149 1.659704e+12 9 private<br>2: 9311888059 -3.045696e+18 -8.601673e+18 Ambler Running running 106383175 149 1.659285e+12 9 private<br>3: 9305033616 5.784667e+17 -8.295883e+18 Ambler Walking walking 106383175 149 1.659202e+12 9 private<br>4: 9296749083 -6.688525e+17 -7.950984e+18 Ambler Running running 106383175 149 1.659094e+12 9 private<\/p><\/blockquote>\n\n\n\n<p>You&#8217;ll get an error like so, which seems to be ok:<\/p>\n\n\n\n<p><em>Warning message:<br>In data.table::rbindlist(read_json(filename)[[1]]$summarizedActivitiesExport, :<br>Column 40 [&#8216;summarizedDiveInfo&#8217;] of item 1 is length 0. This (and 8 others like it) has been filled with NA (NULL for list columns) to make each item uniform.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Garmin export is a deeply nested JSON structure. It only appears to fill in columns where there is data. Like so: The following code will read it to a dataframe: dfactivityId uuidMsb uuidLsb name activityType userProfileId timeZoneId beginTimestamp eventTypeId rule1: 9342780544 -8.608655e+18 -8.443901e+18 Ambler Running running 106383175 149 1.659704e+12 9 private2: 9311888059 -3.045696e+18 -8.601673e+18 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/r-read-garmin-activity-export-summary-to-a-dataframe\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;R: Read Garmin activity export summary to a dataframe&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6],"tags":[450],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6688"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=6688"}],"version-history":[{"count":1,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6688\/revisions"}],"predecessor-version":[{"id":6689,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/6688\/revisions\/6689"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=6688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=6688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=6688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}