Skip to content

Commit

Permalink
limit line lengths to 80 char
Browse files Browse the repository at this point in the history
styler package seemed to break the 80-character rule -- perhaps we should reach out to them. also note there is one lingering long line in test-print-and-summary that I'm not yet sure how to break up
  • Loading branch information
vbaliga committed Oct 22, 2019
1 parent 475cf0d commit f8c85ba
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 125 deletions.
10 changes: 7 additions & 3 deletions R/data_analysis_functions.R
Expand Up @@ -245,7 +245,8 @@ analyze_workloop <- function(x,
x_by_cycle <- lapply(cycle_names, function(cycle) x[x$Cycle == cycle, ])

# create a percent cycle index column
percent_of_cycle <- lapply(x_by_cycle, function(x) seq(0, 100, 100 / (nrow(x) - 1)))
percent_of_cycle <- lapply(x_by_cycle, function(x)
seq(0, 100, 100 / (nrow(x) - 1)))

# work is calculated as the path integral of Force with respect to Position
# (displacement)
Expand Down Expand Up @@ -285,7 +286,9 @@ analyze_workloop <- function(x,
# and force. However since velocity is calculated between two time points,
# corresponding pairs of force measurements are averaged first
# the result is divided by 1000 to convert mW to W
instant_power <- mapply(function(x, v) x$Force * v / 1000, x_by_cycle, filt_velocity,
instant_power <- mapply(function(x, v) x$Force * v / 1000,
x_by_cycle,
filt_velocity,
SIMPLIFY = FALSE
)

Expand Down Expand Up @@ -421,7 +424,8 @@ time_correct <- function(x) {
(utils::tail(x$mtime, 1) - utils::head(x$mtime, 1)) * (x$mtime -
utils::head(x$mtime, 1))
x$Time_Corrected_Power <-
x$Mean_Power - (utils::tail(x$Mean_Power, 1) - utils::head(x$Mean_Power, 1)) /
x$Mean_Power - (utils::tail(x$Mean_Power, 1) - utils::head(x$Mean_Power,
1)) /
(utils::tail(x$mtime, 1) - utils::head(x$mtime, 1)) * (x$mtime -
utils::head(x$mtime, 1))
attr(x, "power_difference") <-
Expand Down
71 changes: 49 additions & 22 deletions R/data_import_functions.R
Expand Up @@ -155,13 +155,16 @@ summary.muscle_stim <- function(object, ...) {
print_muscle_stim_header(object, ...)
cat(paste0("\nFile ID: ", attr(object, "file_id")))
cat(paste0("\nMod Time (mtime): ", attr(object, "mtime")))
cat(paste0("\nSample Frequency: ", attr(object, "sample_frequency"), "Hz\n\n"))
cat(paste0("\nSample Frequency: ", attr(object, "sample_frequency"),
"Hz\n\n"))
cat(paste0("data.frame Columns: \n"))
for (i in 2:ncol(object)) {
cat(paste0(" ", colnames(object)[i], " (", attr(object, "units")[i], ")\n"))
cat(paste0(" ", colnames(object)[i], " (", attr(object, "units")[i],
")\n"))
}
cat(paste0("\nStimulus Offset: ", attr(object, "stimulus_offset"), "s\n"))
cat(paste0("Stimulus Frequency: ", attr(object, "stimulus_frequency"), "Hz\n"))
cat(paste0("Stimulus Frequency: ", attr(object, "stimulus_frequency"),
"Hz\n"))
cat(paste0("Stimulus Width: ", attr(object, "stimulus_width"), "ms\n"))
cat(paste0("Stimulus Pulses: ", attr(object, "stimulus_pulses"), "\n"))
cat(paste0("Gear Ratio: ", attr(object, "gear_ratio"), "\n"))
Expand Down Expand Up @@ -371,7 +374,8 @@ as_muscle_stim <- function(x,
attr(x, "sample_frequency") <- sample_frequency
if (is.na(attr(x, "gear_ratio"))) attr(x, "gear_ratio") <- 1
if (type == "workloop") {
if (is.na(attr(x, "position_inverted"))) attr(x, "position_inverted") <- FALSE
if (is.na(attr(x, "position_inverted")))
attr(x, "position_inverted") <- FALSE
}

# Assign classes and return
Expand Down Expand Up @@ -647,7 +651,9 @@ read_ddf_dir <- function(file_path,
sort_by = "mtime",
...) {
# Generate list of file_names
file_name_list <- list.files(path = file_path, pattern = pattern, full.names = TRUE)
file_name_list <- list.files(path = file_path,
pattern = pattern,
full.names = TRUE)
if (length(file_name_list) == 0) {
stop("No files matching the pattern found at the given directory!")
}
Expand All @@ -661,7 +667,8 @@ read_ddf_dir <- function(file_path,
\nDefaulting to `mtime`.")
sort_by <- "mtime"
}
ms_list <- ms_list[order(unlist(lapply(ms_list, function(i) attr(i, sort_by))))]
ms_list <- ms_list[order(unlist(lapply(ms_list, function(i)
attr(i, sort_by))))]

return(ms_list)
}
Expand Down Expand Up @@ -715,13 +722,19 @@ read_wl_ddf <-
# get info on experimental parameters
stim_table <-
utils::read.table(
text = protocol_table[grepl("Stim", protocol_table$Then.action), "Units"],
text = protocol_table[grepl("Stim", protocol_table$Then.action),
"Units"],
sep = ",",
col.names = c("offset", "frequency", "width", "pulses", "cycle_frequency")
col.names = c("offset",
"frequency",
"width",
"pulses",
"cycle_frequency")
)
cycle_table <-
utils::read.table(
text = protocol_table[grepl("Sine", protocol_table$Then.action), "Units"],
text = protocol_table[grepl("Sine", protocol_table$Then.action),
"Units"],
sep = ",",
col.names = c("frequency", "amplitude", "total_cycles")
)
Expand Down Expand Up @@ -761,7 +774,8 @@ read_twitch_ddf <-
# get info on experimental parameters
stim_table <-
utils::read.table(
text = protocol_table[grepl("Stim", protocol_table$Then.action), "Units"],
text = protocol_table[grepl("Stim", protocol_table$Then.action),
"Units"],
sep = ",",
col.names = c("offset", "width")
)
Expand Down Expand Up @@ -801,7 +815,8 @@ read_tetanus_ddf <-
# get info on experimental parameters
stim_table <-
utils::read.table(
text = protocol_table[grepl("Stim", protocol_table$Then.action), "Units"],
text = protocol_table[grepl("Stim", protocol_table$Then.action),
"Units"],
sep = ",",
col.names = c("offset", "frequency", "width", "length")
)
Expand Down Expand Up @@ -1051,7 +1066,9 @@ read_analyze_wl_dir <- function(file_path,
sort_by = "mtime",
...) {
# Generate list of file_names
file_name_list <- list.files(path = file_path, pattern = pattern, full.names = TRUE)
file_name_list <- list.files(path = file_path,
pattern = pattern,
full.names = TRUE)
if (length(file_name_list) == 0) {
stop("No files matching the pattern found at the given directory!")
}
Expand All @@ -1065,7 +1082,8 @@ read_analyze_wl_dir <- function(file_path,
\nDefaulting to `mtime`.")
sort_by <- "mtime"
}
return(wl_list <- wl_list[order(unlist(lapply(wl_list, function(i) attr(i, sort_by))))])
return(wl_list <- wl_list[order(unlist(lapply(wl_list, function(i)
attr(i, sort_by))))])
}

######################### summarize sequence of work loops #####################
Expand Down Expand Up @@ -1137,23 +1155,32 @@ summarize_wl_trials <- function(wl_list) {
if (class(wl_list)[[1]] != "list") {
stop("Please provide a list of analyzed workloop objects")
}
if (!all(unlist(lapply(wl_list, function(x) "analyzed_workloop" %in% class(x))))) {
if (!all(unlist(lapply(wl_list,
function(x) "analyzed_workloop" %in% class(x))))) {
stop("The provided list includes elements that are
not analyzed workloop objects")
}

summarized <- data.frame(
File_ID = vapply(wl_list, function(i) attr(i, "file_id"), character(1)),
Cycle_Frequency = vapply(wl_list, function(i) attr(i, "cycle_frequency"), numeric(1)),
Amplitude = vapply(wl_list, function(i) attr(i, "amplitude"), numeric(1)),
Phase = vapply(wl_list, function(i) attr(i, "phase"), numeric(1)),
Stimulus_Pulses = vapply(wl_list, function(i) attr(i, "stimulus_pulses"), numeric(1)),
File_ID = vapply(wl_list, function(i) attr(i, "file_id"),
character(1)),
Cycle_Frequency = vapply(wl_list, function(i) attr(i, "cycle_frequency"),
numeric(1)),
Amplitude = vapply(wl_list, function(i) attr(i, "amplitude"),
numeric(1)),
Phase = vapply(wl_list, function(i) attr(i, "phase"),
numeric(1)),
Stimulus_Pulses = vapply(wl_list, function(i) attr(i, "stimulus_pulses"),
numeric(1)),
Stimulus_Frequency = vapply(wl_list, function(i) {
attr(i, "stimulus_frequency")
}, numeric(1)),
mtime = vapply(wl_list, function(i) attr(i, "mtime"), numeric(1)),
Mean_Work = vapply(wl_list, function(i) mean(attr(i, "summary")$Work), numeric(1)),
Mean_Power = vapply(wl_list, function(i) mean(attr(i, "summary")$Net_Power), numeric(1))
mtime = vapply(wl_list, function(i) attr(i, "mtime"),
numeric(1)),
Mean_Work = vapply(wl_list, function(i) mean(attr(i, "summary")$Work),
numeric(1)),
Mean_Power = vapply(wl_list, function(i) mean(attr(i, "summary")$Net_Power),
numeric(1))
)

return(summarized)
Expand Down
3 changes: 2 additions & 1 deletion R/data_transformation_functions.R
Expand Up @@ -155,7 +155,8 @@ select_cycles <- function(x,
}
x <- x[x$Cycle %in% keep_cycles, ]
x$Cycle <- letters[as.factor(x$Cycle)]
if (!all(is.na(attr(x, "units")))) attr(x, "units") <- c(attr(x, "units"), "letters")
if (!all(is.na(attr(x, "units")))) attr(x, "units") <- c(attr(x, "units"),
"letters")
attr(x, "retained_cycles") <- keep_cycles
return(x)
}
Expand Down
8 changes: 4 additions & 4 deletions R/workloopR.R
Expand Up @@ -17,10 +17,10 @@
#' loop experiment (\code{select_cycles()}).
#'
#' Core data analytical functions include \code{analyze_workloop()} for work
#' loop files and \code{isometric_timing()} for twitches. \code{analyze_workloop()}
#' computes instantaneous velocity, net work, instantaneous power, and net power
#' for work loop experiments on a per-cycle basis. \code{isometric_timing()}
#' provides summarization of twitch kinetics.
#' loop files and \code{isometric_timing()} for twitches.
#' \code{analyze_workloop()} computes instantaneous velocity, net work,
#' instantaneous power, and net power for work loop experiments on a per-cycle
#' basis. \code{isometric_timing()} provides summarization of twitch kinetics.
#'
#' Some functions are readily available for batch processing of files. The
#' \code{read_analyze_wl_dir()} function allows for the batch import, cycle
Expand Down
6 changes: 3 additions & 3 deletions docs/articles/Analyzing-workloops.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions docs/articles/Introduction-to-workloopR.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions docs/articles/batch-processing.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/non-ddf-sources.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/paper.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/analyze_workloop.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions docs/reference/workloopR-package.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f8c85ba

Please sign in to comment.