#' helpers
#'
#' @description A fct function
#'
#' @return The return value, if any, from executing the function.
#'
#' @noRd
flip.cage.file.func <- function(f){
library(tidyverse)
f %>%
# not sure if always the first 6 columns
pivot_longer(cols = -c(1:6), names_to = 'var', values_to = 'n') %>%
# prob with kcal_hr_cage# so just remove the first _
mutate(var = gsub('kcal_hr','kcalhr',var)) %>%
# split up the var column into var and cage_id
separate(var, into = c('var','cage_id'), sep = "_") %>%
janitor::clean_names() %>%
# make cage_id numeric
mutate(cage_id = as.numeric(cage_id)) %>%
# fix datetime column
mutate(day = as.Date(date_time_1, format = '%m/%d/%Y'),
dt = as.POSIXct(date_time_1, format = '%m/%d/%Y %H:%M')) %>%
# find the start day; will need this to match with metadata
group_by(cage_id) %>%
mutate(start_day = min(day),
end_day = max(day)) %>%
ungroup() %>%
# get unique subjects because there can be cage_id duplicates
## Assume: no duplicate cage_id in one file
#example: if two cage 1 they will be in different files and since this is ran per file the "start_day" should be correct
mutate(subject_id = paste(cage_id, start_day, sep = '_'))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.