Last active
June 6, 2019 18:15
-
-
Save muschellij2/55f05f708f325f198fb405e90584dcbf to your computer and use it in GitHub Desktop.
Example of using FST data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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