# Using example data from github which requires internet
# takes longer than 5 seconds
if (curl::has_internet()) {
url <- paste0("https://raw.githubusercontent.com/RaphaelHartmann/forceplate/",
"main/data/subj013_block001.txt")
# Safe download, handling potential errors
tryCatch({
filenames <- tempfile(pattern = c("subj013_block001_"),
tmpdir = tempdir(), fileext = ".txt")
download.file(url, filenames)
fp.dt <- segment_fp_data(filenames = filenames, n.trials = 80, baseline.trigger = 128,
baseline.intv = c(0, 215), start.trigger = 128, start.prepend = 0,
stimulus.trigger.list = c(1, 2, 4, 8),
response.trigger.list = c(32, 64),
cond.trigger.list = list(stimulus = c(1, 2, 4, 8),
correctness = c(32, 64)))
# Response-locking with 2 bins before and 2 bins after response onset. Each bin is 100 ms.
tl.dt <- time_lock_stats(fp.dt = fp.dt, vars = c("Mx", "My"),
time.lock.trigger = c(1,2,4,8), bins = c(-150, 150), n.bins = 2,
FUN = list(mean = mean, sd = sd, range = function(x) diff(range(x))))
# Clean up
unlink(filenames)
}, error = function(e) {
message("Failed to download data: ", e$message)
})
}
Run the code above in your browser using DataLab