Skip to content

Commit

Permalink
delete trailing whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomflavio committed Nov 2, 2024
1 parent cb56d67 commit 6666fa6
Show file tree
Hide file tree
Showing 18 changed files with 978 additions and 978 deletions.
14 changes: 7 additions & 7 deletions R/CJS.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,20 @@ breakMatricesByArray <- function(m, arrays, type = c("peers", "all"), verbose =
recipient <- list()
for (i in 1:length(arrays)) {
if ((type == "peers" & !is.null(arrays[[i]]$after.peers)) | (type == "all" & !is.null(arrays[[i]]$all.after))) {

# find out relevant arrays
if (type == "peers")
a.regex <- paste0("^", c(names(arrays)[i], arrays[[i]]$after.peers), "$", collapse = "|")
else
a.regex <- paste0("^", c(names(arrays)[i], arrays[[i]]$all.after), "$", collapse = "|")

# grab only relevant arrays
aux <- lapply(m, function(m_i) m_i[, which(grepl(a.regex, colnames(m_i))), drop = FALSE])

# Failsafe in case some tags are released at one of the peers
keep <- unlist(lapply(m, function(m_i) any(grepl(paste0("^", names(arrays)[i], "$"), colnames(m_i)))))
aux <- aux[keep]

# Failsafe in case there is only one column left
keep <- unlist(lapply(aux, ncol)) > 1
aux <- aux[keep]
Expand Down Expand Up @@ -207,7 +207,7 @@ breakMatricesByArray <- function(m, arrays, type = c("peers", "all"), verbose =
own.zero.check <- unlist(lapply(aux, function(x) sum(x[, 2]) == 0))
peer.zero.check <- unlist(lapply(aux, function(x) sum(x$AnyPeer) == 0))
zero.check <- all(own.zero.check) | all(peer.zero.check)

if (zero.check) {
if (all(own.zero.check) & verbose) {
appendTo(c("Screen", "Warning", "Report"), paste0("No tags passed through array ", names(arrays)[i], ". Skipping efficiency estimations for this array."))
Expand Down Expand Up @@ -308,7 +308,7 @@ assembleMatrices <- function(spatial, movements, status.df, arrays, paths, dotma
output <- lapply(temp, function(x) {
# include transmitters that were never detected
x <- includeMissing(x = x, status.df = status.df)

# sort the rows by the same order as status.df (I think these two lines are not needed, but leaving them in just in case)
link <- sapply(status.df$Transmitter, function(i) grep(paste0("^", i, "$"), rownames(x)))
x <- x[link, ]
Expand All @@ -334,7 +334,7 @@ assembleMatrices <- function(spatial, movements, status.df, arrays, paths, dotma
# If the release sites start in different arrays, trim the matrices as needed
if (length(unique.release.arrays) > 1) {
for(i in 1:length(aux)){ # for each matrix, find the corresponding release site.
the_release_site <- sapply(spatial$release.sites$Standard.name, function(x) grepl(paste0("\\.", x, "$"), names(aux)[i]))
the_release_site <- sapply(spatial$release.sites$Standard.name, function(x) grepl(paste0("\\.", x, "$"), names(aux)[i]))
if(sum(the_release_site) > 1) # if there is more than one matching release site, stop.
stop("Multiple release sites match the matrix name. Make sure that the release sites' names are not contained within the animal groups or within themselves.\n")
# else, find which is the first column to keep. This is tricky for multi-branch sites...
Expand Down
10 changes: 5 additions & 5 deletions R/actel.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#' deploys a set of example files following the structure described in the package
#' vignettes. Namely:
#' \itemize{
#' \item biometrics.csv
#' \item deployments.csv
#' \item spatial.csv
#' \item detections/ (a folder with .csv files)
#' \item biometrics.csv
#' \item deployments.csv
#' \item spatial.csv
#' \item detections/ (a folder with .csv files)
#' }
#'
#' Once the example dataset is created, \code{\link{exampleWorkspace}} also provides
Expand Down Expand Up @@ -64,7 +64,7 @@
#' \code{\link{explore}}, but on top of it, it analyses the animal behaviour.
#' By selecting the arrays that lead to success, you can define whether or not
#' your animals survived the migration. Additional plots help you find out if some
#' animals/tags has been acting odd. Multiple options allow you to tweak the
#' animals/tags has been acting odd. Multiple options allow you to tweak the
#' analysis to fit your study perfectly.
#'
#'
Expand Down
112 changes: 56 additions & 56 deletions R/check.R

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions R/distances.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#' length(suppressWarnings(packageDescription("gdistance"))),
#' length(suppressWarnings(packageDescription("sp"))),
#' length(suppressWarnings(packageDescription("terra"))))
#'
#'
#' missing.packages <- sapply(aux, function(x) x == 1)
#'
#' if (any(missing.packages)) {
Expand Down Expand Up @@ -121,12 +121,12 @@ shapeToRaster <- function(shape, size, spatial = "spatial.csv",
} else {
stop("'shape' must be a .shp file.\n", call. = FALSE)
}

# extend ranges with the buffer
if (!is.null(buffer)) {
OriEx <- terra::ext(shape)
# terra does xmin, xmax, ymin, ymax

if (length(buffer) == 1){
NewEx <- terra::ext(OriEx[1] - buffer, #xmin
OriEx[2] + buffer, #xmax
Expand Down Expand Up @@ -199,7 +199,7 @@ shapeToRaster <- function(shape, size, spatial = "spatial.csv",
message(paste("M: Chosen pixel size:", size, "\nM: Resulting pixel dimensions:"))
message(paste0(capture.output(print(pixel.res)), collapse = "\n"), "\n")

ras <- terra::rast(nrows = pixel.res[2],
ras <- terra::rast(nrows = pixel.res[2],
ncols = pixel.res[1],
xmin = NewEx[1],
xmax = NewEx[2],
Expand Down Expand Up @@ -240,16 +240,16 @@ shapeToRaster <- function(shape, size, spatial = "spatial.csv",


#' DEPRECATED
#'
#'
#' Please use shapeToRaster instead.
#'
#'
#' @inheritParams shapeToRaster
#'
#' @examples
#' \donttest{
#' message("This function is deprecated, please use shapeToRaster instead.")
#' }
#'
#'
#' @return A raster object.
#'
#' @export
Expand Down Expand Up @@ -288,7 +288,7 @@ loadShape <- function(shape, size, spatial = "spatial.csv",
#' length(suppressWarnings(packageDescription("gdistance"))),
#' length(suppressWarnings(packageDescription("sp"))),
#' length(suppressWarnings(packageDescription("terra"))))
#'
#'
#' missing.packages <- sapply(aux, function(x) x == 1)
#'
#' if (any(missing.packages)) {
Expand Down Expand Up @@ -365,7 +365,7 @@ transitionLayer <- function(x, directions = c(16, 8, 4)){
#' length(suppressWarnings(packageDescription("gdistance"))),
#' length(suppressWarnings(packageDescription("sp"))),
#' length(suppressWarnings(packageDescription("terra"))))
#'
#'
#' missing.packages <- sapply(aux, function(x) x == 1)
#'
#' if (any(missing.packages)) {
Expand Down Expand Up @@ -460,7 +460,7 @@ distancesMatrix <- function(t.layer, starters = NULL, targets = starters,

targets <- targets[, c(id.col, coord.x, coord.y)]
colnames(targets) <- c(id.col, "longitude", "latitude")

if (!is.null(id.col)) {
if (!is.na(match(id.col, colnames(starters)))) {
outputRows <- starters[, id.col]
Expand Down Expand Up @@ -495,15 +495,15 @@ distancesMatrix <- function(t.layer, starters = NULL, targets = starters,
#### Create starters and targets spatial dataframes
sp::coordinates(starters) <- ~ longitude + latitude # converts the file to a spatialPoints object
raster::crs(starters) <- raster::crs(t.layer) # sets the crs

sp::coordinates(targets) <- ~ longitude + latitude # converts the file to a spatialPoints object
raster::crs(targets) <- raster::crs(t.layer)

# NOTE: THE LINES ABOVE COULD BE CHANGED ONCE gdistance'S
# NOTE: THE LINES ABOVE COULD BE CHANGED ONCE gdistance'S
# FUNCTIONS START LIKING SF OBJECTS LAYER
# starters <- sf::st_as_sf(starters, coords = c("longitude","latitude"), crs = ...)
# targets <- sf::st_as_sf(targets, coords = c("longitude","latitude"), crs = ...)
# NOTE: currently, transition layer objects are not
# NOTE: currently, transition layer objects are not
# responding correctly to crs requests (e.g. sf::st_crs)

#### Calculate a matrix of distances to each object
Expand All @@ -515,13 +515,13 @@ in the shape file, consider applying a 'buffer' when calculating the transition
will artificially add water space around the shape file.", call. = FALSE)
dist.mat[dist.mat == Inf] <- NA
}

if (row.rename)
rownames(dist.mat) <- outputRows

if (col.rename)
colnames(dist.mat) <- outputCols

if (interactive() & actel) { # nocov start
decision <- userInput("Would you like to save an actel-compatible distances matrix as 'distances.csv' in the current work directory?(y/n) ",
choices = c("y", "n"))
Expand Down Expand Up @@ -620,4 +620,4 @@ completeMatrix <- function(x){
return(x)
}


56 changes: 28 additions & 28 deletions R/explore.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#' @param override A vector of signals for which the user intends to manually
#' define which movement events are valid and invalid.
#' @param detections.y.axis The type of y axis desired for the individual
#' detection plots. While the argument defaults to "auto", it can be hard-set
#' detection plots. While the argument defaults to "auto", it can be hard-set
#' to one of "stations" or "arrays".
#' @param print.releases Logical: Should the release sites be printed in the
#' study area diagrams?
Expand Down Expand Up @@ -161,7 +161,7 @@ explore <- function(
GUI = c("needed", "always", "never"),
save.tables.locally = FALSE,
print.releases = TRUE,
detections.y.axis = c("auto", "stations", "arrays"))
detections.y.axis = c("auto", "stations", "arrays"))
{

# check deprecated argument
Expand All @@ -188,10 +188,10 @@ explore <- function(
checkToken(token = attributes(datapack)$actel.token,
timestamp = attributes(datapack)$timestamp)

if (length(min.per.event) > 1)
if (length(min.per.event) > 1)
appendTo(c('screen', 'warning', 'report'),
'explore() only has array movements but two values were set for min.per.event. Disregarding second value.')

aux <- checkArguments(dp = datapack,
tz = tz,
min.total.detections = min.total.detections,
Expand Down Expand Up @@ -377,7 +377,7 @@ explore <- function(
output <- checkMinimumN(movements = movements[[tag]], tag = tag, min.total.detections = min.total.detections,
min.per.event = min.per.event[1], n = counter)

output <- checkImpassables(movements = output, tag = tag, bio = bio, detections = detections.list[[tag]], n = counter,
output <- checkImpassables(movements = output, tag = tag, bio = bio, detections = detections.list[[tag]], n = counter,
spatial = spatial, dotmat = dotmat, GUI = GUI, save.tables.locally = save.tables.locally)

output <- checkJumpDistance(movements = output, bio = bio, tag = tag, dotmat = dotmat, paths = paths, arrays = arrays,
Expand All @@ -387,8 +387,8 @@ explore <- function(
if (do.checkSpeeds) {
temp.valid.movements <- simplifyMovements(movements = output, tag = tag, bio = bio, discard.first = discard.first,
speed.method = speed.method, dist.mat = dist.mat)
output <- checkSpeeds(movements = output, tag = tag, detections = detections.list[[tag]], n = counter,
valid.movements = temp.valid.movements, speed.warning = speed.warning,
output <- checkSpeeds(movements = output, tag = tag, detections = detections.list[[tag]], n = counter,
valid.movements = temp.valid.movements, speed.warning = speed.warning,
speed.error = speed.error, GUI = GUI, save.tables.locally = save.tables.locally)
rm(temp.valid.movements)
}
Expand All @@ -397,9 +397,9 @@ explore <- function(
output <- checkInactiveness(movements = output, tag = tag, detections = detections.list[[tag]], n = counter,
inactive.warning = inactive.warning, inactive.error = inactive.error,
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 <- overrideValidityChecks(moves = movements[[tag]], tag = tag, detections = detections.list[[tag]],
GUI = GUI, save.tables.locally = save.tables.locally, n = counter)
} # nocov end
return(output)
Expand All @@ -417,7 +417,7 @@ explore <- function(

aux <- list(valid.movements = valid.movements,
spatial = spatial,
rsp.info = list(bio = bio,
rsp.info = list(bio = bio,
analysis.type = "explore"))
times <- getTimes(input = aux, move.type = "array", event.type = "arrival", n.events = "first")
rm(aux)
Expand All @@ -434,7 +434,7 @@ explore <- function(
deployments <- do.call(rbind.data.frame, deployments)

# extra info for potential RSP analysis
rsp.info <- list(analysis.type = "explore", analysis.time = the.time,
rsp.info <- list(analysis.type = "explore", analysis.time = the.time,
bio = bio, tz = tz, actel.version = utils::packageVersion("actel"))

if (!is.null(override))
Expand All @@ -457,7 +457,7 @@ explore <- function(
}

if (interactive()) { # nocov start
decision <- userInput(paste0("Would you like to save a copy of the results to ", resultsname, "?(y/n) "),
decision <- userInput(paste0("Would you like to save a copy of the results to ", resultsname, "?(y/n) "),
choices = c("y", "n"), hash = "# save results?")
} else { # nocov end
decision <- "n"
Expand All @@ -466,10 +466,10 @@ explore <- function(
if (decision == "y") { # nocov start
appendTo(c("Screen", "Report"), paste0("M: Saving results as '", resultsname, "'."))
if (attributes(dist.mat)$valid)
save(bio, detections, valid.detections, spatial, deployments, arrays,
save(bio, detections, valid.detections, spatial, deployments, arrays,
movements, valid.movements, times, rsp.info, dist.mat, file = resultsname)
else
save(bio, detections, valid.detections, spatial, deployments, arrays,
save(bio, detections, valid.detections, spatial, deployments, arrays,
movements, valid.movements, times, rsp.info, file = resultsname)
} else {
appendTo(c("Screen", "Report"), paste0("M: Skipping saving of the results."))
Expand All @@ -494,24 +494,24 @@ explore <- function(

biometric.fragment <- printBiometrics(bio = bio)

printDot(dot = dot,
spatial = spatial,
printDot(dot = dot,
spatial = spatial,
print.releases = print.releases)

individual.plots <- printIndividuals(detections.list = detections,
individual.plots <- printIndividuals(detections.list = detections,
movements = movements,
valid.movements = valid.movements,
spatial = spatial,
rsp.info = rsp.info,
y.axis = detections.y.axis)

circular.plots <- printCircular(times = timesToCircular(times),
circular.plots <- printCircular(times = timesToCircular(times),
bio = bio)

if (any(sapply(valid.detections, function(x) any(!is.na(x$Sensor.Value))))) {
sensor.plots <- printSensorData(detections = valid.detections,
sensor.plots <- printSensorData(detections = valid.detections,
spatial = spatial,
rsp.info = rsp.info,
rsp.info = rsp.info,
colour.by = detections.y.axis)
} else {
sensor.plots <- NULL
Expand Down Expand Up @@ -582,7 +582,7 @@ explore <- function(
jobname <- paste0(gsub(" |:", ".", as.character(Sys.time())), ".actel.log.txt")

if (interactive() & !report) { # nocov start
decision <- userInput(paste0("Would you like to save a copy of the analysis log to ", jobname, "?(y/n) "),
decision <- userInput(paste0("Would you like to save a copy of the analysis log to ", jobname, "?(y/n) "),
choices = c("y", "n"), hash = "# save job log?")
} else { # nocov end
decision <- "n"
Expand All @@ -593,14 +593,14 @@ explore <- function(
} # nocov end

output <- list(bio = bio,
detections = detections,
valid.detections = valid.detections,
spatial = spatial,
deployments = deployments,
detections = detections,
valid.detections = valid.detections,
spatial = spatial,
deployments = deployments,
arrays = arrays,
movements = movements,
valid.movements = valid.movements,
times = times,
movements = movements,
valid.movements = valid.movements,
times = times,
rsp.info = rsp.info)

if (attributes(dist.mat)$valid)
Expand Down
Loading

0 comments on commit 6666fa6

Please sign in to comment.