Skip to content

Instantly share code, notes, and snippets.

@muschellij2
Last active June 6, 2019 18:15
Show Gist options
  • Save muschellij2/55f05f708f325f198fb405e90584dcbf to your computer and use it in GitHub Desktop.
Save muschellij2/55f05f708f325f198fb405e90584dcbf to your computer and use it in GitHub Desktop.
Example of using FST data
library(ActivityIndex)
library(fst)
library(lubridate)
library(data.table)
filename = system.file("extdata","sample_GT3X+.csv.gz",
package = "ActivityIndex")
res = ActivityIndex::ReadGT3XPlus(filename)
data = res$Raw
data$DT = paste(data$Date, data$Time)
data$DT = ymd_hms(data$DT)
setkey(data, DT)
format(object.size(data), units = "Mb")
df = as.data.frame(data)
format(object.size(df), units = "Mb")
#######################
# Write out fst files
#######################
fst_file = tempfile(fileext = ".fst")
fst::write_fst(df, fst_file)
fst_df = fst::fst(fst_file)
class(fst_df)
format(object.size(fst_df), units = "Mb")
is.data.frame(fst_df)
object.size(fst_df)
sub_df = fst_df[ fst_df$DT >= ymd_hms("2012-06-27 11:00:00") &
fst_df$DT <= ymd_hms("2012-06-27 12:00:00"), ]
is.data.frame(sub_df)
format(object.size(sub_df), units = "Mb")
# use data.table
dt_fst_file = tempfile(fileext = ".fst")
fst::write_fst(data, dt_fst_file)
fst_dt = fst::fst(dt_fst_file)
class(fst_dt)
fst_dt
format(object.size(fst_dt), units = "Mb")
# key is preserved
dt = read_fst(dt_fst_file, as.data.table = TRUE)
key(dt)
format(object.size(dt), units = "Mb")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment