Skip to content

Commit

Permalink
Merge pull request #26 from droglenc/Restart-work
Browse files Browse the repository at this point in the history
Restart work
  • Loading branch information
droglenc authored Oct 6, 2018
2 parents dcb80e2 + f533986 commit ed9e79a
Show file tree
Hide file tree
Showing 70 changed files with 397 additions and 261 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ cran-comments.md
^cran-comments

man/figures/logo.png
inst/sticker/
inst/sticker/
github/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ tests/testthat/Rplots*.*
# Documentation folder (because using Travis-CI autodocumentation for webpage)
docs/*
# RDS files for vignettes (can be re-made from code)
vignettes/MeasureRadii/*.rds
vignettes/MeasureRadii/*.rds
vignettes/MeasureRadii/zzzTempRdsFiles/
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# RFishBC 0.0.12.9000 ongoing
* `combineData()`: Modified. Changed so that an age-0 fish with all plus-growth is still included in the returned data.frame when `deletePlusGrowth=TRUE` (the `ann` and `rad` variables will both be `NA`). Thanks to Ben Neely.
* `digitizeRadii()`: Modified. Removed restriction that one point be selected as an annulus, which allows for handling age-0 fish (addresses [#25](https://github.com/droglenc/RFishBC/issues/25); thanks to Ben Neely for the suggestion). Removed the `q` and `r` button equivalencies for `f` and `d`. Added the ability for the user to start over (resulting in no file to be written, but the current image stays live; uses the `z` key) (addresses [#22](https://github.com/droglenc/RFishBC/issues/22); thanks to Ben Neely for the suggestion). Added the ability for the user to abort a processing (resulting in no file to be written and moving to the next image if using multiple images; uses the `q` key) (addresses [#24](https://github.com/droglenc/RFishBC/issues/24); thanks to Ben Neely for the suggestion).
* `findScalingFactor()`: Modified. Changed to allow the user to abort or restart the process, similar to for `digitizeRadii()`.

# RFishBC 0.0.12 ongoing
* Excluded many of the interactive lines from the coverage statistics. Updated other tests (aiming for comprehensiveness).
Expand Down
6 changes: 3 additions & 3 deletions R/RFBCoptions.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#' @param reset A logical that will reset the values to their \dQuote{factory-fresh} defaults if \code{TRUE}.
#' @param \dots An arbitrary number of \code{argument}=\code{value} pairs where \code{argument} is one of the argument names and \code{value} is the new value for the argument. See details and examples.
#'
#' @return None, but the list in \code{RFBCoptions} will be modified.
#'
#' @details The arguments that can be set with this function are:
#' \itemize{
#' \item{\code{reading}: }{A single character string (or an object that can be coerced to a character) that identifies the reading for a structure. If the structure will be read multiple times, then this may be used to specify the particular reading. Defaults to \code{NULL}. Used in \code{\link{digitizeRadii}}.}
Expand All @@ -16,7 +18,7 @@
#' \item{\code{sepWindow}: }{A single logical that indicates whether the structure image should be opened in a separate window (\code{=TRUE}) or not (\code{=FALSE}). Defaults to \code{TRUE}. Used in \code{\link{digitizeRadii}}, \code{\link{showDigitizedImage}}, and \code{\link{findScalingFactor}}.}
#' \item{\code{windowSize}: }{A single numeric used to set the size of the largest dimension for the window in which the structure image is opened if \code{sepWindow=TRUE}. This size will be the width for wider images and the height for taller images. The other dimension will be set relative to this so that the image is displayed in its native aspect ratio. Defaults to 7 inches. Used in \code{\link{digitizeRadii}} and \code{\link{findScalingFactor}}.}
#' \item{\code{closeWindow}: }{A single logical that indicates whether the structure image should be closed (if it was in a separate window) (\code{=TRUE}) or not (\code{=FALSE}). Defaults to \code{TRUE}. Used in \code{\link{digitizeRadii}} and \code{\link{findScalingFactor}}.}
#' \item{\code{popID}: }{A single logical that indicates if the fish ID dialog box (only on Windows if no \code{ID} is given in \code{\link{digitizeRadii}}) is populated with the image file name sans the extension. This is useful for when the image name is the fish ID. Defaults to \code{TRUE}. Used in \code{\link{digitizeRadii}}.}
#' \item{\code{popID}: }{A single logical that indicates if the fish ID dialog box (only on Windows if no \code{ID} is given in \code{\link{digitizeRadii}}) is populated with a guess at the fish ID. The guess is from using the pattern in \code{IDpattern} (see below) on the image file name sans the extension. This may be useful for when the image name contains the fish ID (and no other numbers). Defaults to \code{TRUE}. Used in \code{\link{digitizeRadii}}.}
#' \item{\code{IDpattern}: }{A single regular expression that indicates how to extract a possible fish ID from an image file name. Defaults to selecting all characters after the last underscore in the image file name (sans extension). Used in \code{\link{digitizeRadii}}.}
#' \item{\code{scalingFactor}: }{A single numeric used to convert measurements on the structure image to actual measurements on the structure. Measurements on the structure image will be multiplied by this value. Ignored if \code{scaleBar=TRUE}. Defaults to \code{1}. Used in \code{\link{digitizeRadii}}.}
#' \item{\code{scaleBar}: }{A single logical that indicates whether the user will be prompted to select the endpoints of a scale-bar on the structure image. If \code{TRUE}, then must also use \code{scaleBarLength}. If \code{FALSE}, then consider using \code{scalingFactor}. Defaults to \code{FALSE}. Used in \code{\link{digitizeRadii}}.}
Expand Down Expand Up @@ -51,8 +53,6 @@
#'
#' @seealso \code{\link{digitizeRadii}} and \code{\link{showDigitizedImage}}
#'
#' @return None, but the list in \code{RFBCoptions} will be modified.
#'
#' @author Derek H. Ogle, \email{derek@@derekogle.com}
#'
#' @export
Expand Down
25 changes: 18 additions & 7 deletions R/RFishBC-internals.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ iSelectPt <- function(numPts,msg1,msg2,
## Internal function for handling key press event
keyPress <- function(key) {
n <- nrow(dat)
if (key %in% c("f","q")) {
### User requesting to be done with the process
if (key=="f") {
if (!is.null(numPts)) {
### Check to see if number of points is correct (if numPts given)
if (n!=numPts) {
tmpmsg <- paste("Must select exactly",numPts,"points. ")
if (n<numPts) message(tmpmsg,"Please select ",numPts-n," more point(s).")
Expand All @@ -148,13 +150,24 @@ iSelectPt <- function(numPts,msg1,msg2,
} else return(invisible(1))
} else return(invisible(1))
}
if (key %in% c("d","r")) {
### User requesting to delete or remove a point
if (key=="d") {
if (n>=1) {
graphics::points(y~x,data=dat[n,],pch=pch.del,col=col.del,cex=cex.sel)
dat <<- dat[-n,]
}
NULL
}
### User requesting to abort
if (key=="q") {
dat <<- "ABORT"
return(invisible(1))
}
### User requesting to start over with a clean slate
if (key=="z") {
dat <<- "RESTART"
return(invisible(1))
}
}
## Main function
dat <- data.frame(x=NULL,y=NULL)
Expand All @@ -176,11 +189,7 @@ iScalingFactorFromScaleBar <- function(msg2,knownLength,pixW2H,
pch.del=pch.del,col.del=col.del,
snap2Transect=FALSE,slpTransect=NULL,
intTransect=NULL,slpPerpTransect=NULL)
if (nrow(sbPts)<2) {
STOP("Two endpoints were not selected for the scale-bar.")
} else if (nrow(sbPts)>2) {
STOP("Only two endpoints may be selected for the scale-bar.")
} else {
if (is.data.frame(sbPts)) { # data.frame returned b/c not abort/restarted
## Show the user-selected marking on the image
graphics::lines(y~x,data=sbPts,col=col.scaleBar,lwd=lwd.scaleBar)
## Find distances in x- and y- directions,
Expand All @@ -189,6 +198,8 @@ iScalingFactorFromScaleBar <- function(msg2,knownLength,pixW2H,
disty <- sbPts$y[2]-sbPts$y[1]
## Return a list (scaling factor is known / distance between points)
list(sbPts=sbPts,scalingFactor=knownLength/sqrt(distx^2+disty^2))
} else { # data.frame not returned b/c abort/restarted
sbPts # just return the sbPts object
}
} # nocov end

Expand Down
16 changes: 13 additions & 3 deletions R/combineData.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#' @param outFormat A string that indicates the output format for the combined data. The \code{"wide"} (DEFAULT) format has one-radius-per-line (i.e., each radial measurement for a fish in on a separate row), whereas the \code{"long"} format has one-fish-per-line (i.e., each radial measurement for a fish is in a separate column).
#' @param deletePlusGrowth A logical that indicates whether the radial measurement that corresponds to \dQuote{plus-growth} should be deleted from the returned data.frame (\code{TRUE}; DEFAULT) or not (\code{FALSE}).
#'
#' @details A detailed description of its use is in \href{http://derekogle.com/RFishBC/articles/MeasureRadii/collectRadiiData.html}{this vignette} on the \href{http://derekogle.com/RFishBC/index.html}{RFishBC website}. The list of R data file names may be efficiently created with \code{\link{listFiles}} as described in that vignette. The R data file names may also be selected from a dialog box if using Windows.
#'
#' @return A data.frame that contains the radii data created with \code{\link{digitizeRadii}} for all files given in \code{nms}.
#'
#' @details A detailed description of its use is in \href{http://derekogle.com/RFishBC/articles/MeasureRadii/collectRadiiData.html}{this vignette} on the \href{http://derekogle.com/RFishBC/index.html}{RFishBC website}. The list of R data file names may be efficiently created with \code{\link{listFiles}} as described in that vignette. The R data file names may also be selected from a dialog box if using Windows.
#'
#' @author Derek H. Ogle, \email{derek@@derekogle.com}
#'
#' @export
Expand Down Expand Up @@ -39,7 +39,17 @@ combineData <- function(nms,outFormat=c("long","wide"),deletePlusGrowth=TRUE) {
}
}
## Remove radial measurement related to plus-growth (same as radcap anyways)
if (deletePlusGrowth) d <- d[d$ann<=d$agecap,]
if (deletePlusGrowth) {
## Get all age-0 fish and include no annulus or radius, but the radcap
d1 <- d[d$agecap==0,]
if (nrow(d1)>0) d1$ann <- d1$rad <- NA
## Get all >age-0 fish and then remove the plus-growth
d2 <- d[d$agecap>0,]
d2 <- d2[d2$ann<=d2$agecap,]
## Put the age-0 and >age-0 fish back together, sort by ID and ann
d <- rbind(d1,d2)
d <- d[order(d$id,d$ann),]
}
## Convert to wide (one-fish-per-line) format
if (outFormat=="wide") {
d <- tidyr::spread(d,key=ann,value=rad,sep="rad")
Expand Down
Loading

0 comments on commit ed9e79a

Please sign in to comment.