We are currently trying to get GGIR to read in a csv file in order to run that through in place of the bin files and we are getting two errors that we are unsure how to fix. Our code is below!
library(GGIR)
#specify directory with actigraphy csv files
act_dir <- "Z:/GENEActiv/TEST_GGIR/Test8/"
#=========================
# CLEAN CSV FILES
#=========================
#make output directory
todaysdate=format(Sys.Date(),"%Y-%m-%d")
output_dir <- paste0("Z:/GENEActiv/TEST_RESULTS_GGIR_", todaysdate)
dir.create(output_dir)
#read in individual subject files
act_files<-list.files(act_dir, pattern = "*.csv") #create list of csv files
act_dfiles<-paste0(act_dir,act_files) #append directory to file name
n = as.numeric(length(act_files)) #n subjects
#make directory for revised files
r_act_dir<- paste0(act_dir, "revised_", todaysdate)
dir.create(r_act_dir)
setwd(r_act_dir)
# read in each raw file and append to create dataset like actiware combined export
for(i in 1:n){
filename<-act_dfiles[i]
x<- read.csv(filename, header = FALSE) # Read in raw act file; add csv
y<- x[-c(51:80),] # Remove rows that will result in duplicate header row names
newfilename<-paste0(substr(act_files[i],1,17), "_rev.csv") # Update filename
write.table(y,newfilename , sep=",", # Save edited csv file
row.names=FALSE, col.names=FALSE)
}
#=========================
# RUN GGIR FOR EACH SUBJECT
#========================
#read in individual subject files
act_files1<-list.files(r_act_dir, pattern = "*_rev.csv") # Create list of actig csv files
act_dfiles1<-paste0(r_act_dir,"/",act_files1) # Append directory to file name
nn = as.numeric(length(act_files1)) # n subjects
#data.list <- mget(grep("act_dfiles1",ls(),value=TRUE),envir=.GlobalEnv)
#assign("out", output_dir, envir=.GlobalEnv)
#==========================
# START LOOP
#==========================
library(dplyr)
#lapply(data.list,runGGIR)
#==========================
# Call GGIR -- NOTE NEED TO MODIFY THIS TO BE A WRAPPER FUNCTION.
#==========================
#runGGIR<-function(input_file){
GGIR(
mode=c(1,2,3,4,5), # which part of GGIR to run, GGIR is constructed in 5 parts
datadir= c("Z:/GENEActiv/TEST_GGIR/Test8/revised_2022-08-30"), #csv file
outputdir= c("Z:/GENEActiv/TEST_RESULTS_GGIR/output_Test8"), #output directory
do.report=c(2,4,5), #specify which reports need to be generated
#=====================
# read.myacc.csv arguments
#=====================
rmc.nrow=Inf,
rmc.skip = 70, # Indicates how many rows to skip to get to time series data
rmc.dec=".", # Decimal separator, "." for USA, "," for EU
rmc.firstrow.acc = 71, # First row of acceleration data
rmc.unit.acc = , # Character with unit of acceleration values: "g", "mg", or "bit".
rmc.col.acc = 2:4, # columns with acceleration data
rmc.desiredtz = "America/New_York", # Time zone
#header info
#
https://rdrr.io/cran/GGIR/src/R/read.myacc.csv.R rmc.firstrow.header = 1, # First row (number) of the header. Leave blank (default) if the file does not have a header.
rmc.header.length = 70, # If file has header, specify header length (numeric).
rmc.headername.sf = "Measurement Frequency", # If file has a header, row name (character) under which the sample frequency can be found.
rmc.headername.sn = "Device Unique Serial Code", # If file has a header, row name (character) under which the serial number can be found.
rmc.headername.recordingid = "Subject Code", # If file has a header, row name (character) under which the recording ID can be found.
#rmc.header.structure = "--", # Character used to split the header name from the header value, e.g. ":" or " ".
#time information
rmc.col.time = 1, # Scalar with column (number) in which the timestamps are stored. Leave in default setting if timestamps are not stored.
rmc.unit.time = "POSIX", # Character with unit of timestamps: "POSIX", "UNIXsec" (seconds since origin, see argument rmc.origin), "character", or "ActivPAL" (exotic timestamp format only used in the ActivPAL activity monitor).
rmc.format.time = "%Y-%m-%d %H:%M:%OS", # Character string giving a date-time format as used by . Only used for rmc.unit.time: character and POSIX.
#acceleration stored in bits
rmc.bitrate = 12, # Numeric: If unit of acceleration is a bit then provide bit rate, e.g. 12 bit.
rmc.dynamic_range = 8, # Numeric, if unit of acceleration is a bit then provide dynamic range deviation in g from zero, e.g. +/-6g would mean this argument needs to be 6. If you give this argument a character value the code will search the file header for elements with a name equal to the character value and use the corresponding numeric value next to it as dynamic range.
rmc.unsignedbit = FALSE, # Boolean, if unsignedbit = TRUE means that bits are only positive numbers. If unsignedbit = FALSE then bits are both positive and negative.
#temperature
rmc.col.temp = 7, # Scalar with column (number) in which the temperature is stored. Leave in default setting if no temperature is avaible.
rmc.unit.temp = "C", # Character with unit of temperature values: (K)elvin, (C)elsius, or (F)ahrenheit.
#timegaps and resampling
rmc.check4timegaps = FALSE, # Boolean to indicate whether gaps in time should be imputed with zeros.
rmc.doresample = FALSE, # Boolean to indicate whether to resample the data based on the available timestamps and extracted sample rate from the file header
interpolationType=1,
#=====================
# Part 2
#=====================
strategy = 1, # Indicates experiment design. Set to 1 (based on hrs del.start to hrs del.end)
hrs.del.start = 0, # Numeric indicating when wear started in hrs (relative to experiment start)
hrs.del.end = 0, # Numeric indicating when wear stopped in hrs (relative to experiement end)
maxdur = 9, # Max number of days to expect in the data file
includedaycrit = 16, # Hrs of valid data per day (measured midnight to midnight)
qwindow=c(0,24), # Numeric or character indicating hrs over which data are to be calculated (e.g. c(0,24) for 0hrs to 24hrs)
mvpathreshold =c(100), # Numeric acceleration threshold for mod/vig physical activity)
bout.metric = 6, # Numeric indicating a strategy for bout detection (leave at 6 for LEAP/RAM)
excludefirstlast = FALSE, # Boolean with TRUE = first and last nights of tracking ignored
includenightcrit = 4, # Hrs of valid data per night (measured noon to noon)
#=====================
# Part 3 + 4
#=====================
def.noc.sleep = c(1), # Numeric which indicates the time window during which inactivity = sleep (only use if no sleep log)
outliers.only = TRUE, # Boolean with FALSE = visualize all available nights in the data
criterror = 4, # Numeric specifying min number hrs diff between sleep log and accelerometer to be included in visualization
do.visual = TRUE, # Boolean with TRUE = generate a pdf with the overlap between sleep log and accelerometer
#loglocation = "Z:/GENEActiv/TEST_GGIR/SleepLog_Test", #Location of sleep log
#colid = 1 # Sleep log col with ID
#coln1 = 2, # Sleep log col with first line of data
#nnights = 8, # Num nights to expect in sleep log
#sleeplogsep = ",", # File seperator
#=====================
# Part 5
#=====================
threshold.lig = c(30), # Numeric defining threshold for light physical activity
threshold.mod = c(100), # Numeric defining threshold for mod physical activity
threshold.vig = c(400), # Numeric defining threshold for vig physical activity
boutcriter = 0.8, # Numeric defining what fraction of a bout must be above mvpa threshold
boutcriter.in = 0.9, # Numeric defining what fraction of a bout must be below the light threshold
boutcriter.lig = 0.8, # Numeric defining what fraction of a bout must be between the light and mod threshold
boutcriter.mvpa = 0.8, # Numeric defining what fraction of a bout must be above the mvpa threshold
boutdur.in = c(1,10,30), # Numeric defining duration of inactivity bouts (in min) to be extracted
boutdur.lig = c(1,10), # Numeric defining duration of light activity bouts (in min) to be extracted
boutdur.mvpa = c(1), # Numeric defining duration of mvpa bouts (in min) to be extracted
includedaycrit.part5 = 2/3, # Numeric min number of required valid hrs in a day
save_ms5rawlevels=TRUE, # Boolean with TRUE = save raw epoch data
save_ms5raw_format="csv", # Indicates format in which to save raw epoch data
#=====================
# Visual report
#=====================
timewindow = c("WW"), # Time frame over which summary stats are derived ("MM" = midnight to midnight, "WW" = waketime to waketime, "MM, WW" = both)
visualreport=TRUE # Boolean with TRUE = generate visual report
)
#for (i in 1:nn) {
# infile=act_dfiles1[i]
# runGGIR(infile)
#}
Error in GGIR(mode = c(1, 2, 3, 4, 5), datadir = c("Z:/GENEActiv/TEST_GGIR/Test8/revised_2022-08-30"), :
argument is missing, with no default