Skip to content

Instantly share code, notes, and snippets.

View nacnudus's full-sized avatar

Duncan Garmonsway nacnudus

View GitHub Profile
@nacnudus
nacnudus / xml_to_df.R
Last active March 22, 2023 05:01
Convert xml to a nested data frame
``` r
library(xml2)
library(dplyr)
library(purrr)
library(stringr)
# From the root node:
# If has_children, then recurse.
# Otherwise, attributes, value and children (nested) to data frame.
@nacnudus
nacnudus / gist:6723265
Last active December 24, 2015 01:19
ggplot axis time format HH:mm:ss
timeHMS_formatter <- function(x) {
x[is.na(x)] <- 0
h <- trunc(x * 24)
m <- trunc(x * 24 * 60)
s <- x * 24 * 60 * 60 %% 60
s <- round(s, 2)
lab <- sprintf('%02d:%02d:%02d', h, m, s) # Format the strings as HH:MM:SS
lab <- gsub('^00:', '', lab) # Remove leading 00: if present
lab <- gsub('^0', '', lab) # Remove leading 0 if present
}