R/import_data.R
import_actigraph_csv_chunked.Rd
import_actigraph_csv_chunked
imports the raw multi-channel accelerometer data
stored in Actigraph raw csv format. It supports files from the following
devices: GT3X, GT3X+, GT3X+BT, GT9X, and GT9X-IMU.
import_actigraph_csv_chunked(
filepath,
in_voltage = FALSE,
header = TRUE,
has_ts = TRUE,
chunk_samples = 180000
)
string. The filepath of the input data.The first column of the input data should always include timestamps.
set as TRUE only when the input Actigraph csv file is in analog quantized format and need to be converted into g value
boolean. If TRUE, the input csv file will have column names in the first row.
boolean. If TRUE, the input csv file should have a timestamp column at first.
number. The number of samples in each chunk. Default is 180000.
list. The list contains two items. The first item is a generator
function that each time it is called, it will return a data.frame of the
imported chunk. The second item is a close
function which you can
call at any moment to close the file loading.
For old device (GT3X) that stores accelerometer values as digital voltage. The function will convert the values to \(g\) unit using the following equation.
$$x_g = \frac{x_{voltage}r}{(2 ^ r) - \frac{v}{2}}$$
Where \(v\) is the max voltage corresponding to the max accelerometer value that can be found in the meta section in the csv file; \(r\) is the resolution level which is the number of bits used to store the voltage values. \(r\) can also be found in the meta section in the csv file.
This function is a File IO function that is used to import data from Actigraph devices during algorithm validation.
Other File I/O functions:
export_to_actilife()
,
import_actigraph_count_csv()
,
import_actigraph_csv()
,
import_actigraph_meta()
,
import_activpal3_csv()
,
import_enmo_csv()
,
import_mhealth_csv_chunked()
,
import_mhealth_csv()
default_ops = options()
options(digits.secs=3)
# Use the actigraph csv file shipped with the package
filepath = system.file('extdata', 'actigraph_timestamped.csv', package='MIMSunit')
# Check original file format
readLines(filepath)[1:15]
#> [1] "------------ Data File Created By ActiGraph GT3X+ ActiLife v6.13.3 Firmware v2.5.0 date format M/d/yyyy at 40 Hz Filter Normal -----------"
#> [2] "Serial Number: CLE2B20130009"
#> [3] "Start Time 11:27:00"
#> [4] "Start Date 6/14/2018"
#> [5] "Epoch Period (hh:mm:ss) 00:00:00"
#> [6] "Download Time 15:16:42"
#> [7] "Download Date 6/14/2018"
#> [8] "Current Memory Address: 0"
#> [9] "Current Battery Voltage: 4.21 Mode = 12"
#> [10] "--------------------------------------------------"
#> [11] "Timestamp,Accelerometer X,Accelerometer Y,Accelerometer Z"
#> [12] "6/14/2018 12:08:39.725,-0.009,-0.053,-0.988"
#> [13] "6/14/2018 12:08:39.750,-0.009,-0.053,-0.982"
#> [14] "6/14/2018 12:08:39.775,-0.009,-0.053,-0.988"
#> [15] "6/14/2018 12:08:39.800,-0.009,-0.053,-0.982"
# Example 1: Load chunks every 2000 samples
results = import_actigraph_csv_chunked(filepath, chunk_samples=2000)
next_chunk = results[[1]]
close_connection = results[[2]]
# Check data as chunks, you can see chunks are shifted at each iteration.
n = 1
repeat {
df = next_chunk()
if (nrow(df) > 0) {
print(paste('chunk', n))
print(paste("df:", df[1, 1], '-', df[nrow(df),1]))
n = n + 1
}
else {
break
}
}
#> [1] "chunk 1"
#> [1] "df: 2018-06-14 12:08:39.725 - 2018-06-14 12:09:29.700"
#> [1] "chunk 2"
#> [1] "df: 2018-06-14 12:09:30.000 - 2018-06-14 12:10:19.975"
#> [1] "chunk 3"
#> [1] "df: 2018-06-14 12:10:20.275 - 2018-06-14 12:10:44.425"
# Close connection after reading all the data
close_connection()
# Example 2: Close loading early
results = import_actigraph_csv_chunked(filepath, chunk_samples=2000)
next_chunk = results[[1]]
close_connection = results[[2]]
# Check data as chunks, you can see chunk time is shifting forward at each iteration.
n = 1
repeat {
df = next_chunk()
if (nrow(df) > 0) {
print(paste('chunk', n))
print(paste("df:", df[1, 1], '-', df[nrow(df),1]))
n = n + 1
close_connection()
}
else {
break
}
}
#> [1] "chunk 1"
#> [1] "df: 2018-06-14 12:08:39.725 - 2018-06-14 12:09:29.700"
# Restore default options
options(default_ops)