Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reformat migration.R to 80c #143

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,8 @@ checkReport <- function(report){
#'
#' @keywords internal
#'
checkFirstDetBackFromRelease <- function(movements, tag, bio, detections, arrays, spatial, GUI, save.tables.locally, n) {
event(type = "debug", "Running checkFirstDetBackFromRelease.")
checkFirstMove <- function(movements, tag, bio, detections, arrays, spatial, GUI, save.tables.locally, n) {
event(type = "debug", "Running checkFirstMove.")
# NOTE: The NULL variables below are actually column names used by data.table.
# This definition is just to prevent the package check from issuing a note due unknown variables.
Valid <- NULL
Expand Down
2 changes: 1 addition & 1 deletion R/explore.R
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ explore <- function(
dist.mat = dist.mat, GUI = GUI, save.tables.locally = save.tables.locally)
}
} else { # nocov start
output <- overrideValidityChecks(moves = movements[[tag]], tag = tag, detections = detections.list[[tag]],
output <- overrideChecks(moves = movements[[tag]], tag = tag, detections = detections.list[[tag]],
GUI = GUI, save.tables.locally = save.tables.locally, n = counter)
} # nocov end
return(output)
Expand Down
76 changes: 76 additions & 0 deletions R/helper.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
#' Parse argument and its value as a string
#'
#' used to store the calls of the main actel functions as a string
#'
#' @param arg the argument to be parsed
#' @param arg_val an optional argument, to use as the value of the argument
#' used in "arg". Used when arg is, in itself, a complex object provided
#' by the user. E.g. a datapack, or an argument of preload.
#'
#' @return A string showing the argument and its value, as it would have been
#' inputted into the R console.
#'
#' @keywords internal
#'
parse_arg <- function(arg, arg_val) {
output <- paste0(deparse(substitute(arg)), " = ")

if (!missing(arg_val)) {
return(paste0(output, arg_val))
}
if (is.null(arg)) {
return(paste0(output, "NULL"))
}

if (is.character(arg)) {
a <- "'"
b <- "', '"
} else {
a <- ""
b <- ", "
}
if (is.list(arg)) {
output <- paste0(output, parse_list(arg))
} else {
if (length(arg) == 1) {
output <- paste0(output, a, arg, a)
} else {
output <- paste0(output, "c(", a, paste0(arg, collapse = b), a, ")")
}
}
return(output)
}

#' Helper to parse list arguments
#'
#' Used inside [parse_arg()] to properly parse list arguments
#'
#' @inheritParams parse_arg
#'
#' @return A string showing the list as it would have been
#' inputted into the R console.
#'
#' @keywords internal
#'
parse_list <- function(arg) {
aux <- sapply(1:length(arg), function(i) {
if (is.character(arg[[i]])) {
a <- "'"
b <- "', '"
} else {
a <- ""
b <- ", "
}
name_i <- names(arg)[i]
content <- paste(arg[[i]], collapse = b)
if (length(arg[[i]]) == 1) {
output_i <- paste0("'", name_i,"' = ", a, content, a)
} else {
output_i <- paste0("'", name_i,"' = c(", a, content, a, ")")
}
return(output_i)
})
output <- paste0("list(", paste0(aux, collapse = ", "), ")")
return(output)
}

#' collapse event indexes into ranges
#'
#' @param x a numerical vector
Expand Down
1,458 changes: 889 additions & 569 deletions R/migration.R

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions R/residency.R
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ residency <- function(
dist.mat = dist.mat, GUI = GUI, save.tables.locally = save.tables.locally)
}
} else {
output <- overrideValidityChecks(moves = movements[[tag]], tag = tag, detections = detections.list[[tag]], # nocov
output <- overrideChecks(moves = movements[[tag]], tag = tag, detections = detections.list[[tag]], # nocov
GUI = GUI, save.tables.locally = save.tables.locally, n = counter) # nocov
}
return(output)
Expand All @@ -494,12 +494,21 @@ residency <- function(

aux <- sectionMovements(movements = movements[[i]], spatial = spatial, valid.dist = attributes(dist.mat)$valid)

aux <- checkMinimumN(movements = aux, tag = tag, min.total.detections = 0, # don't run the minimum total detections check here.
if (!is.null(aux)) {
# don't run the minimum total detections check here (i.e. set it to 0);
# that's already done when compiling the array movements.
aux <- checkMinimumN(movements = aux, tag = tag, min.total.detections = 0,
min.per.event = min.per.event[2], n = counter)

output <- checkSMovesN(secmoves = aux, tag = tag, section.warning = section.warning, section.error = section.error, GUI = GUI,
save.tables.locally = save.tables.locally, n = counter)
return(output)
output <- checkSMovesN(secmoves = aux, tag = tag,
section.warning = section.warning,
section.error = section.error, GUI = GUI,
save.tables.locally = save.tables.locally,
n = counter)
return(output)
} else {
return(NULL)
}
})
names(section.movements) <- names(movements)

Expand Down
4 changes: 2 additions & 2 deletions R/user_interaction.R
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,8 @@ transferValidity <- function(from, to) { # nocov start
#'
#' @keywords internal
#'
overrideValidityChecks <- function(moves, detections, tag, GUI, save.tables.locally, n) { # nocov start
event(type = "debug", "Starting overrideValidityChecks.")
overrideChecks <- function(moves, detections, tag, GUI, save.tables.locally, n) { # nocov start
event(type = "debug", "Starting overrideChecks.")
trigger <- paste0("M: Override has been triggered for tag ", tag,
" ", n, ". Entering full manual mode.")

Expand Down
3 changes: 2 additions & 1 deletion man/assembleOutput.Rd

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

6 changes: 4 additions & 2 deletions man/assembleSectionOverview.Rd

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

6 changes: 4 additions & 2 deletions man/assembleTimetable.Rd

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

6 changes: 3 additions & 3 deletions man/checkFirstDetBackFromRelease.Rd → man/checkFirstMove.Rd

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

6 changes: 4 additions & 2 deletions man/countBackMoves.Rd

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

91 changes: 55 additions & 36 deletions man/migration.Rd

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

6 changes: 3 additions & 3 deletions man/overrideValidityChecks.Rd → man/overrideChecks.Rd

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

23 changes: 23 additions & 0 deletions man/parse_arg.Rd

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

19 changes: 19 additions & 0 deletions man/parse_list.Rd

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

Loading
Loading