Skip to content

Commit

Permalink
Code style update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Luque committed Nov 1, 2024
1 parent cb24903 commit 4a15732
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: diveMove
Type: Package
Title: Dive Analysis and Calibration
Version: 1.6.4
Version: 1.6.5
Depends: R (>= 4.4.0), methods, stats4
Suggests: knitr, lattice, pander, rmarkdown, tinytest
Imports: geosphere, KernSmooth, plotly, quantreg, uniReg
Expand Down
26 changes: 13 additions & 13 deletions R/AllMethod.R
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,9 @@ setMethod("plotDiveModel",
depths[a.crit:length(x)], col="lightblue")
legend("top", ncol=2, title=paste("Dive:", diveNo),
legend=c("original", "smoothed",
"descent", "ascent"), lty=c(1, 2, 1, 1),
"descent", "ascent"), lty=c(1, 2, 1, 1),
col=c("black", "green",
"blue", "lightblue"), cex=0.7)
"blue", "lightblue"), cex=0.7)
plot(times.deriv, depths.deriv, xlab="Time index",
ylab="First derivative", type="l", cex=0.3)
points(times.deriv[descent], depths.deriv[descent],
Expand All @@ -450,7 +450,7 @@ setMethod("plotDiveModel",
v=c(times[d.crit], times[a.crit]), lty=2)
text(2, c(d.crit.rate, a.crit.rate),
labels=c(expression(paste("descent ", hat(q))),
expression(paste("ascent ", hat(q)))),
expression(paste("ascent ", hat(q)))),
pos=c(3, 1), cex=0.7)
text(c(times[d.crit], times[a.crit]), 0,
labels=c("descent", "ascent"), pos=1, cex=0.7)
Expand Down Expand Up @@ -527,7 +527,7 @@ setMethod("boutsNLSll", signature(obj="numeric"),
setMethod("boutinit", signature(obj="data.frame"),
function(obj, x.break, plot=TRUE, ...) {
nproc <- length(x.break)
if (nproc > 2) stop ("x.break must be of length 1 or 2")
if (nproc > 2) stop("x.break must be of length 1 or 2")
procf <- cut(obj$x, breaks=c(min(obj$x), x.break,
max(obj$x)),
include.lowest=TRUE, right=TRUE)
Expand Down Expand Up @@ -838,7 +838,7 @@ setMethod("plotBouts", signature(fit="mle", obj="Bouts"),
for (bec.i in seq_len(length(becx))) {
text(becx[bec.i], becy[bec.i], pos=4, offset=1,
paste(paste("bec_", bec.i - 1, "=", sep=""),
round(becx[bec.i], 2), sep=""),
round(becx[bec.i], 2), sep=""),
bty="n", cex=0.8)
}
}
Expand Down Expand Up @@ -1435,11 +1435,11 @@ setReplaceMethod("ccData", signature(x="TDR", value="data.frame"),
###_ + Subsetting
setMethod("[", signature(x="TDR", i="numeric", j="missing", drop="missing"),
function(x, i, j, ..., drop) {
new(class(x), file=getFileName(x), dtime=getDtime(x), time=getTime(x)[i],
depth=getDepth(x)[i],
concurrentData=tryCatch(getCCData(x)[i, , drop=FALSE],
error=function(k) data.frame()))
})
new(class(x), file=getFileName(x), dtime=getDtime(x),
time=getTime(x)[i], depth=getDepth(x)[i],
concurrentData=tryCatch(getCCData(x)[i, , drop=FALSE],
error=function(k) data.frame()))
})


###_ + Generators and Summaries
Expand Down Expand Up @@ -1516,11 +1516,11 @@ setMethod("[", signature(x="TDR", i="numeric", j="missing", drop="missing"),
##' file=srcfn, speed=TRUE)
"createTDR" <- function(time, depth,
concurrentData=data.frame(matrix(ncol=0,
nrow=length(time))),
nrow=length(time))),
speed=FALSE, dtime, file)
{
if (missing(dtime)) dtime <- .getInterval(time)
if(speed) {
if (speed) {
new("TDRspeed", time=time, depth=depth, concurrentData=concurrentData,
dtime=dtime, file=file)
} else {
Expand Down Expand Up @@ -1562,7 +1562,7 @@ setMethod("extractDive", signature(obj="TDR", diveNo="numeric",
id="numeric"), # for TDR object
function(obj, diveNo, id) {
if (length(id) != length(getTime(obj))) {
stop ("id and obj must have equal number of rows")
stop("id and obj must have equal number of rows")
}
okpts <- .diveIndices(id, unique(diveNo))
if (is(obj, "TDRspeed")) {
Expand Down
10 changes: 5 additions & 5 deletions R/austFilter.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
## --------------------------------------------------------------------
## Author: Sebastian Luque
## --------------------------------------------------------------------
if (!window %% 2) stop ("window size must be an odd number")
if (nrow(x) < window) stop ("there are fewer rows than window size")
if (!window %% 2) stop("window size must be an odd number")
if (nrow(x) < window) stop("there are fewer rows than window size")
tpos <- window %/% 2 # test subscript - 1
testfun <- function(k) { # k=matrix with group to test
mid <- tpos + 1 # subscript of pt to test
Expand Down Expand Up @@ -205,9 +205,9 @@
## --------------------------------------------------------------------
## Author: Sebastian Luque
## --------------------------------------------------------------------
if (!window %% 2) stop ("window size must be an odd number")
if (!window %% 2) stop("window size must be an odd number")
wdw.errmess <- "there are fewer rows than window size"
if (nrow(x) < window) stop (wdw.errmess)
if (nrow(x) < window) stop(wdw.errmess)
tpos <- window %/% 2 # test subscript - 1
ref <- c(-seq(tpos), seq(tpos)) # reference points for test
travel.fun <- function(k) { # k=subscripts
Expand All @@ -222,7 +222,7 @@

while (any(rmsSwitch)) { # stop when switch is all FALSE
switchidx <- which(rmsSwitch)
if ((length(switchidx) + (tpos * 2)) < window) stop (wdw.errmess)
if ((length(switchidx) + (tpos * 2)) < window) stop(wdw.errmess)
testrows.new <- testrows[rmsSwitch]
idx <- seq_along(testrows.new) # index the above
testidx.mtx <- testidx <- c(idx, sapply(ref, "+", idx))
Expand Down
2 changes: 1 addition & 1 deletion R/calibrate.R
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
smooth.par=0.1, knot.factor=3,
descent.crit.q=0, ascent.crit.q=0)
{
if (!is(x, "TDR")) stop ("x is not a TDR object")
if (!is(x, "TDR")) stop("x is not a TDR object")
mCall <- match.call()
depth <- getDepth(x)
time <- getTime(x)
Expand Down
6 changes: 3 additions & 3 deletions R/detPhase.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@
## Final run to determine times with all corrected activities
finacts <- .rleActivity(time, act, interval)
nphase <- length(levels(finacts[[1]]))
if(act[1] == "L" & act[length(act)] == "L") {
if (act[1] == "L" & act[length(act)] == "L") {
message("Record is complete\n", nphase, " phases detected")
} else {
if(act[1] != "L" & act[length(act)] != "L") {
if (act[1] != "L" & act[length(act)] != "L") {
message("Record is truncated at the beginning and at the end\n",
nphase, " phases detected")
} else {
if(act[1] != "L") {
if (act[1] != "L") {
message("Record is truncated at the beginning\n", nphase,
" phases detected")
} else {
Expand Down
16 changes: 8 additions & 8 deletions R/diveMove-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@ NULL
##' @section \code{bouts2.nls}:
##' For \code{bouts2.nls}, use \code{\link{fitNLSbouts}}.
"bouts2.nls" <- function(lnfreq, start, maxiter) {
.Deprecated("fitNLSbouts", package="diveMove",
.Deprecated("fitNLSbouts", package="diveMove",
msg=paste("'bouts2.nls' is now deprecated in favor of",
"the new method 'fitNLSbouts'.",
"Please see help(fitNLSbouts)"))
fitNLSbouts(lnfreq, start=start, maxiter=maxiter)
fitNLSbouts(lnfreq, start=start, maxiter=maxiter)
}

##' @rdname diveMove-deprecated
##' @section \code{bec2}:
##' For \code{bec2}, use \code{\link{bec}}.
"bec2" <- function(fit) {
.Deprecated("bec", package="diveMove",
.Deprecated("bec", package="diveMove",
msg=paste("'bec2' is now deprecated in favor of",
"the new generalized method 'bec'.",
"Please see help(bec)"))
bec(fit)
bec(fit)
}

##' @rdname diveMove-deprecated
##' @section \code{bec3}:
##' For \code{bec3}, use \code{\link{bec}}.
"bec3" <- function(fit) {
.Deprecated("bec", package="diveMove",
.Deprecated("bec", package="diveMove",
msg=paste("'bec3' is now deprecated in favor of",
"the new generalized method 'bec'.",
"Please see help(bec)"))
bec(fit)
bec(fit)
}

##' @rdname diveMove-deprecated
Expand All @@ -69,11 +69,11 @@ NULL
##' @section \code{bouts3.nls}:
##' For \code{bouts3.nls}, use \code{\link{fitNLSbouts}}.
"bouts3.nls" <- function(lnfreq, start, maxiter) {
.Deprecated("fitNLSbouts", package="diveMove",
.Deprecated("fitNLSbouts", package="diveMove",
msg=paste("'bouts3.nls' is now deprecated in favor of",
"the new method 'fitNLSbouts'.",
"Please see help(fitNLSbouts)"))
fitNLSbouts(lnfreq, start=start, maxiter=maxiter)
fitNLSbouts(lnfreq, start=start, maxiter=maxiter)
}

##' @rdname diveMove-deprecated
Expand Down
20 changes: 10 additions & 10 deletions R/plotTDR.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@
nights <- .night(time, sunrise.time, sunset.time)
nconcurVars <- ifelse(is.null(concurVars), 0, ncol(concurVars))
plotrows <- nconcurVars + 1
ncheight <- 1.35 * (1/plotrows)
lheights <- c(rep((1 - ncheight)/nconcurVars, nconcurVars), ncheight)
ncheight <- 1.35 * (1 / plotrows)
lheights <- c(rep((1 - ncheight) / nconcurVars, nconcurVars), ncheight)
mardepthonly <- c(4, 4, 1, 1) + 0.1 # for depth plot only
mardepthmore <- c(4, 4, -0.1, 1) + 0.1 # for depth plot and more vars
martop <- c(-0.1, 4, 1, 1) + 0.1 # for top plot
marnontop <- c(-0.1, 4, -0.1, 1) + 0.1 # for plots between depth and top one
orig <- structure(0, class=class(time), tzone=attr(time, "tzone"))
"plot.fun" <- function(xlim, ylim) {
xticks <- orig + seq(from=xlim[1], to=xlim[2], length=20)
if(is.null(concurVars)) {
if (is.null(concurVars)) {
par(las=1, bty="n", mar=mardepthonly, ...)
} else {
par(las=1, bty="n", mar=mardepthmore, ...)
Expand Down Expand Up @@ -118,7 +118,7 @@
}
if (!interact) {
rx <- range(as.numeric(time)) # max and min of dates
xlim <- if(is.null(xlim)) rx else as.numeric(xlim)
xlim <- if (is.null(xlim)) rx else as.numeric(xlim)
ylim <- if (is.null(depth.lim)) {
rev(range(depth, na.rm=TRUE))
} else rev(depth.lim)
Expand All @@ -128,7 +128,7 @@
stop("tcltk support is absent")
rx <- range(as.numeric(time)) # max and min of dates
diffrx <- diff(rx)
xlim <- x10 <- if(is.null(xlim)) { # define xlim if not there already
xlim <- x10 <- if (is.null(xlim)) { # define xlim if not there already
rx + (diffrx * 0.01) # add 1% to each side
} else as.numeric(xlim)
xlmid <- xm0 <- mean(xlim) # two vars with date range midpoint
Expand All @@ -145,16 +145,16 @@
replot <- function(...) {
xZ <<- as.numeric(tcltk::tclvalue(xZoom))
xM <<- as.numeric(tcltk::tclvalue(xlmid))
xr.half <- (xr0/2) * 100/xZ
xr.half <- (xr0 / 2) * 100 / xZ
xlim <- xM + c(-xr.half, xr.half)
yTop <<- as.numeric(tcltk::tclvalue(yMax))
ylim <- c(yTop, ylim[2])
plot.fun(xlim=xlim, ylim=ylim)
}
replot.maybe <- function(...) {
if(as.numeric(tcltk::tclvalue(xZoom)) != xZ ||
as.numeric(tcltk::tclvalue(xlmid)) != xM ||
as.numeric(tcltk::tclvalue(yMax)) != yTop) replot()
if (as.numeric(tcltk::tclvalue(xZoom)) != xZ ||
as.numeric(tcltk::tclvalue(xlmid)) != xM ||
as.numeric(tcltk::tclvalue(yMax)) != yTop) replot()
}
coords <- list()
zocrange <- function() {
Expand Down Expand Up @@ -193,7 +193,7 @@
tpan.s <- tcltk::tkscale(xmid.frame, command=replot.maybe,
from=xm0 - xr0, to=xm0 + xr0,
showvalue=FALSE, variable=xlmid,
resolution=xr0/2000, length=200,
resolution=xr0 / 2000, length=200,
orient="horiz")
## Maximum depth selection
maxdep.l <- tcltk::tklabel(dep.frame, text="Max. Depth (m)")
Expand Down
8 changes: 4 additions & 4 deletions R/plotZOC.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
## --------------------------------------------------------------------
## Author: Sebastian P. Luque
## --------------------------------------------------------------------
if (!is(x, "TDR")) stop ("x is not a TDR object")
if (!is(x, "TDR")) stop("x is not a TDR object")
time <- getTime(x)
depth <- getDepth(x)
if (length(time) != nrow(zoc.filter)) {
stop ("x and zoc.filter must have the same number of records")
stop("x and zoc.filter must have the same number of records")
}
nfilters <- ncol(zoc.filter)
if (missing(xlim)) xlim <- range(time)
Expand Down Expand Up @@ -85,8 +85,8 @@
## --------------------------------------------------------------------
## Author: Sebastian P. Luque
## --------------------------------------------------------------------
if (!is(x, "TDR")) stop ("x is not a TDR object")
if (!is(y, "TDRcalibrate")) stop ("y is not a TDRcalibrate object")
if (!is(x, "TDR")) stop("x is not a TDR object")
if (!is(y, "TDRcalibrate")) stop("y is not a TDRcalibrate object")
time.in <- getTime(x)
depth.in <- getDepth(x)
time.out <- getTime(getTDR(y))
Expand Down
2 changes: 1 addition & 1 deletion R/readLocs.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
inLocs <- read.csv(locations, ...)
} else {
if (! is.data.frame(locations)) {
stop ("'locations' must be a data.frame, path to a file, or a connection")
stop("'locations' must be a data.frame, path to a file, or a connection")
} else {inLocs <- locations}
}
if (missing(loc.idCol)) {
Expand Down
4 changes: 2 additions & 2 deletions R/readTDR.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
basename(summary(file)$description),
basename(file))
} else {
stop ("'file' must be a path to a file, or a connection")
stop("'file' must be a path to a file, or a connection")
}
rawdat <- read.csv(file, ...)
names(rawdat) <- tolower(names(rawdat))
rawdat.ncol <- seq(ncol(rawdat))
dtpasted <- paste(rawdat[, dateCol], rawdat[, timeCol])
datetime <- as.POSIXct(strptime(dtpasted, format=dtformat), tz=tz)
origint <- .getInterval(datetime)
if(!identical(all.equal(origint, subsamp), TRUE)) {
if (!identical(all.equal(origint, subsamp), TRUE)) {
steptim <- as.numeric((subsamp) / origint)
stepind <- seq(from=1, to=length(datetime), by=round(steptim))
datetime <- datetime[stepind]
Expand Down
2 changes: 1 addition & 1 deletion R/runquantile.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
np <- length(probs)
k <- as.integer(k)
type <- as.integer(type)
if (k <= 1) return (rep(x, n, np))
if (k <= 1) return(rep(x, n, np))
if (k > n) k <- n
if (is.na(type) || (type < 1 | type > 9))
warning("'type' outside allowed range [1,9]; changing 'type' to ",
Expand Down
2 changes: 1 addition & 1 deletion R/speedStats.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
mspeed <- mean(speed, na.rm=TRUE)
tdist <- sum(difft * speed, na.rm=TRUE)
if (!missing(vdist)) {
angle <- asin(ifelse(vdist < tdist, vdist/tdist, NA)) * (180 / pi)
angle <- asin(ifelse(vdist < tdist, vdist / tdist, NA)) * (180 / pi)
cbind(tdist=tdist, mean.speed=mspeed, angle=angle)
} else {
cbind(tdist=tdist, mean.speed=mspeed, angle=NA)
Expand Down
4 changes: 2 additions & 2 deletions R/stampDive.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
## --------------------------------------------------------------------
## Author: Sebastian Luque
## --------------------------------------------------------------------
if (!is(x, "TDRcalibrate")) stop ("x needs to be a TDRcalibrate object")
if (!is(x, "TDRcalibrate")) stop("x needs to be a TDRcalibrate object")
act <- getGAct(x, "activity")
diveid <- getDAct(x, "dive.id")

Expand All @@ -36,7 +36,7 @@
phaseid[act == "L"] <- 0 # dry phase.id should be 0
## make a sequence for phase.id > 0 from 1:number of such phases
phase.no[act != "L"] <- rep(seq(along=table(phaseid[phaseid > 0])),
table(phaseid[phaseid > 0]))
table(phaseid[phaseid > 0]))
ok <- match(unique(diveid[diveid > 0]), diveid) # required subscripts
phase.no <- phase.no[ok]
activity <- act[ok]
Expand Down

0 comments on commit 4a15732

Please sign in to comment.