Skip to content

Instantly share code, notes, and snippets.

@selfawaresoup
Last active April 7, 2024 10:20
Show Gist options
  • Save selfawaresoup/d2b49306fa1f96a33e1d3cac1e7ffe9f to your computer and use it in GitHub Desktop.
Save selfawaresoup/d2b49306fa1f96a33e1d3cac1e7ffe9f to your computer and use it in GitHub Desktop.
Make Apple Health data available for analysis in R as an RDA file.
# This can take quite a long time to run
library(xml2)
library(tidyverse)
read_xml("apple_health_export/export.xml") -> x
x %>% xml_find_all(".//Record") %>%
xml_attrs %>%
bind_rows %>%
mutate(
type = factor(type),
value = as.double(value),
unit = factor(unit),
creationDate = as.POSIXct(creationDate),
startDate = as.POSIXct(startDate),
endDate = as.POSIXct(endDate)
) -> health_data
save(file="health_data.rda", list=c("health_data"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment