Skip to content

Instantly share code, notes, and snippets.

@retostauffer
Created May 15, 2024 05:49
Show Gist options
  • Save retostauffer/077db602767d8b10550068d3624693dc to your computer and use it in GitHub Desktop.
Save retostauffer/077db602767d8b10550068d3624693dc to your computer and use it in GitHub Desktop.
rm(list = objects())
library("annex")
library("devtools")
# ---------------------------------------------------------------
# Check if the correct version is installed
# ---------------------------------------------------------------
stopifnot("Requires (development) version 0.2.14" =
as.character(packageVersion("annex")) == "0.2.14")
# ---------------------------------------------------------------
# Simulating some random data
# ---------------------------------------------------------------
N <- 30
data <- data.frame(datetime = as.POSIXct("2024-01-01 01:00", tz = "UTC") + seq_len(N) * 1800,
CO2 = runif(N, 300, 600),
T = rnorm(N, 20, 4),
RH = runif(N, 0, 1),
PMOther55 = sample(1:10, N, replace = TRUE),
PMOther66 = sample(1:10, N, replace = TRUE),
Other = sample(1:1000, N),
Other1 = sample(1:1000, N),
Other2 = sample(-100:100, N))
print(head(data))
# Faking config file csv
conf <- "column,variable,study,unit,home,room
datetime,datetime,NA,NA,NA,NA
CO2,CO2,demo,ppm,home5,BED
T,T,demo,C,home5,BED
RH,RH,demo,-,home5,BED
PMOther55,PMOther55,demo,NA,home5,Bed
PMOther66,PMOther66,demo,NA,home5,Bed
Other,Other,demo,NA,home5,Bed
Other1,Other1,demo,NA,home5,Bed
Other2,Other2,demo,NA,home5,Bed"
(conf <- read.csv(text = conf))
# Checking config file, should now accept OtherXX and PMOtherXX
conf <- annex_check_config(conf)
# Preparing the data.frame
prepared_df <- annex_prepare(data, conf)
# Calculate annex DF using this long formula
f <- Other + Other2 + Other1 + T + PMOther55 + PMOther66 ~ datetime | study + room + home
annex_df <- annex(f, data = prepared_df, tz = "UTC")
# Calculating statistics
stats <- annex_stats(annex_df)
stats[, c(4:7, 18:22)]
# Writing statistics to XLSX file
if (file.exists("__testOther.xlsx")) file.remove("__testOther.xlsx")
annex_write_stats(stats, file = "__testOther.xlsx", user = 666)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment