Skip to content
Open
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Package: dssd
Depends: R (>= 3.6.0)
Imports:
sf,
ggplot2,
Expand Down Expand Up @@ -27,7 +28,6 @@ Description: Creates survey designs for distance sampling surveys. These
BugReports: https://github.com/DistanceDevelopment/dssd/issues
License: GPL (>=2)
Encoding: UTF-8
RoxygenNote: 7.3.2
Collate:
'Class.Constructors.R'
'Coverage.Grid.R'
Expand Down Expand Up @@ -63,3 +63,4 @@ Collate:
'point.coords.as.dataframe.R'
'run.coverage.R'
'write.transects.R'
Config/roxygen2/version: 8.0.0
8 changes: 4 additions & 4 deletions R/Class.Constructors.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ make.region <- function(region.name = "region",
}
if(length(strata.name) < length(shape) && length(shape) > 1){
strata.name <- LETTERS[1:length(shape)]
warning("Automatically naming strata as insufficient strata names provided. Assigned strata names:", paste(strata.name, collapse = ", "), call. = F, immediate. = T)
warning("Automatically naming strata as insufficient strata names provided. Assigned strata names:", paste(strata.name, collapse = ", "), call. = FALSE)
}else if(length(strata.name) == 0 && length(shape) == 1){
strata.name <- region.name
}else if(length(strata.name) > length(shape)){
Expand Down Expand Up @@ -99,7 +99,7 @@ make.region <- function(region.name = "region",
}else if(strata.count != length(strata.name)){
if(length(sf.shape) <= 26){
strata.name <- LETTERS[1:length(sf.shape[[sf.column]])]
warning("Automatically naming strata as no (or incorrect number of) strata names provided. Assigned strata names: ", paste(strata.name, collapse = ", "), call. = F, immediate. = T)
warning("Automatically naming strata as no (or incorrect number of) strata names provided. Assigned strata names: ", paste(strata.name, collapse = ", "), call. = FALSE)
}else{
stop("Too many strata (>26) for strata names to be assigned default names, please provide the correct number of strata names.", call. = FALSE)
}
Expand Down Expand Up @@ -375,7 +375,7 @@ make.design <- function(region = make.region(), transect.type = "line", design =
}else if(transect.type %in% c("Point", "point", "Point Transect", "point transect")){
# Check line length not supplied
if(length(line.length) > 0){
warning("Argument line.length not applicable to point transect designs.", immediate. = TRUE, call. = FALSE)
warning("Argument line.length not applicable to point transect designs.", call. = FALSE)
}
#Create point transect object
design <- new(Class="Point.Transect.Design", region, truncation, design, spacing, samplers, effort.allocation, design.angle, edge.protocol, coverage.grid)
Expand Down Expand Up @@ -423,7 +423,7 @@ make.coverage <- function(region = make.region(),
}
if(length(spacing) > 0 && length(n.grid.points) > 0){
if(n.grid.points != 1000){
warning("Both spacing and n.grid.points specified, n.grid.point will be disregarded.", call. = FALSE, immediate. = TRUE)
warning("Both spacing and n.grid.points specified, n.grid.point will be disregarded.", call. = FALSE)
}
n.grid.points <- numeric(0)
}
Expand Down
2 changes: 1 addition & 1 deletion R/Coverage.Grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ setMethod(
sf.column <- attr(x@grid, "sf_column")
plot(x@grid[[sf.column]], add = add, col = col, pch = pch)
}else{
warning("No grid points to plot", call. = F, immediate. = F)
warning("No grid points to plot", call. = FALSE)
}
invisible(x)
}
Expand Down
2 changes: 1 addition & 1 deletion R/Line.Transect.Design.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ gt.LT.fun.body <- function(object, quiet, ...){
#Need to retain transect IDs as well as strata for lines
if(length(transects) == 0){
if(!quiet){
warning("No samplers generated.", immediate. = T, call. = FALSE)
warning("No samplers generated.", call. = FALSE)
}
return(NULL)
}
Expand Down
50 changes: 25 additions & 25 deletions R/Line.Transect.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ setMethod(
#}
plot(x@samplers[[sf.column.samps]], add = add, col = col, lwd = lwd)
}else{
warning("No samplers to plot", call. = F, immediate. = F)
warning("No samplers to plot", call. = FALSE)
}
invisible(x)
}
Expand All @@ -113,45 +113,45 @@ setMethod(
title <- paste("\n Strata ", strata.names[strat], ":", sep = "")
len.title <- nchar(title)
underline <- paste(" ", paste(rep("_", (len.title-3)), collapse = ""), sep = "")
cat(title, fill = T)
cat(underline, fill = T)
cat(title, fill = TRUE)
cat(underline, fill = TRUE)
design <- switch(object@design[strat],
"random" = "randomly located transects",
"systematic" = "systematically spaced parallel transects",
"eszigzag" = "equal spaced zigzag",
"eszigzagcom" = "complementaty equal spaced zigzags",
"segmentedgrid" = "segmented grid")
cat("Design: ", design, fill = T)
cat("Design: ", design, fill = TRUE)
if(object@design[strat] %in% c("systematic", "eszigzag", "eszigzagcom", "segmentedgrid")){
cat("Spacing: ", object@spacing[strat], fill = T)
cat("Spacing: ", object@spacing[strat], fill = TRUE)
}
cat("Line length:", object@line.length[strat], fill = T)
cat("Line length:", object@line.length[strat], fill = TRUE)
if(object@design[strat] == "segmentedgrid"){
cat("Segment length: ", object@seg.length[strat], fill = T)
cat("Segment threshold: ", object@seg.threshold[strat], fill = T)
cat("Segment length: ", object@seg.length[strat], fill = TRUE)
cat("Segment threshold: ", object@seg.threshold[strat], fill = TRUE)
}
cat("Trackline length:", object@trackline[strat], fill = T)
cat("Cyclic trackline length:", object@cyclictrackline[strat], fill = T)
cat("Number of samplers: ", object@samp.count[strat], fill = T)
cat("Design angle: ", object@design.angle[strat], fill = T)
cat("Edge protocol: ", object@edge.protocol[strat], fill = T)
cat("Covered area: ", object@cov.area[strat], fill = T)
cat("Strata coverage: ", round((object@cov.area[strat]/object@strata.area[strat])*100,2), "%", fill = T, sep = "")
cat("Strata area: ", object@strata.area[strat], fill = T)
cat("Trackline length:", object@trackline[strat], fill = TRUE)
cat("Cyclic trackline length:", object@cyclictrackline[strat], fill = TRUE)
cat("Number of samplers: ", object@samp.count[strat], fill = TRUE)
cat("Design angle: ", object@design.angle[strat], fill = TRUE)
cat("Edge protocol: ", object@edge.protocol[strat], fill = TRUE)
cat("Covered area: ", object@cov.area[strat], fill = TRUE)
cat("Strata coverage: ", round((object@cov.area[strat]/object@strata.area[strat])*100,2), "%", fill = TRUE, sep = "")
cat("Strata area: ", object@strata.area[strat], fill = TRUE)
}
#Now print totals
cat("\n Study Area Totals:", fill = T)
cat(" _________________", fill = T)
cat("Line length:", sum(object@line.length, na.rm = T), fill = T)
cat("Trackline length:", sum(object@trackline, na.rm = T), fill = T)
cat("Cyclic trackline length:", sum(object@cyclictrackline, na.rm = T), fill = T)
cat("Number of samplers: ", sum(object@samp.count, na.rm = T), fill = T)
cat("\n Study Area Totals:", fill = TRUE)
cat(" _________________", fill = TRUE)
cat("Line length:", sum(object@line.length, na.rm = TRUE), fill = TRUE)
cat("Trackline length:", sum(object@trackline, na.rm = TRUE), fill = TRUE)
cat("Cyclic trackline length:", sum(object@cyclictrackline, na.rm = TRUE), fill = TRUE)
cat("Number of samplers: ", sum(object@samp.count, na.rm = TRUE), fill = TRUE)
if(length(object@effort.allocation) > 0){
cat("Effort allocation: ", paste(object@effort.allocation*100, collapse = "%, "), "%", fill = T, sep = "")
cat("Effort allocation: ", paste(object@effort.allocation*100, collapse = "%, "), "%", fill = TRUE, sep = "")
}
cat("Covered area: ", sum(object@cov.area, na.rm = T), fill = T)
cat("Covered area: ", sum(object@cov.area, na.rm = TRUE), fill = TRUE)
index <- which(!is.na(object@cov.area))
cat("Average coverage: ", round((sum(object@cov.area[index])/sum(object@strata.area))*100,2), "%", fill = T, sep = "")
cat("Average coverage: ", round((sum(object@cov.area[index])/sum(object@strata.area))*100,2), "%", fill = TRUE, sep = "")
invisible(object)
}
)
2 changes: 1 addition & 1 deletion R/Point.Transect.Design.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ setMethod(
}
if(length(transects) == 0){
if(!quiet){
warning("No samplers generated.", immediate. = T, call. = FALSE)
warning("No samplers generated.", call. = FALSE)
}
index <- numeric(0)
}else{
Expand Down
34 changes: 17 additions & 17 deletions R/Point.Transect.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ setMethod(
if(length(x@samplers) > 0){
plot(x@samplers[[sf.column]], add = add, col = col, pch = pch)
}else{
warning("No samplers to plot", call. = F, immediate. = F)
warning("No samplers to plot", call. = FALSE)
}
invisible(x)
}
Expand All @@ -87,32 +87,32 @@ setMethod(
title <- paste("\n Strata ", strata.names[strat], ":", sep = "")
len.title <- nchar(title)
underline <- paste(" ", paste(rep("_", (len.title-3)), collapse = ""), sep = "")
cat(title, fill = T)
cat(underline, fill = T)
cat(title, fill = TRUE)
cat(underline, fill = TRUE)
design <- switch(object@design[strat],
"random" = "randomly located transects",
"systematic" = "systematically spaced transects")
cat("Design: ", design, fill = T)
cat("Design: ", design, fill = TRUE)
if(object@design[strat] == "systematic"){
cat("Spacing: ", object@spacing[strat], fill = T)
cat("Spacing: ", object@spacing[strat], fill = TRUE)
}
cat("Number of samplers: ", object@samp.count[strat], fill = T)
cat("Design angle: ", object@design.angle[strat], fill = T)
cat("Edge protocol: ", object@edge.protocol[strat], fill = T)
cat("Covered area: ", object@cov.area[strat], fill = T)
cat("Strata coverage: ", round((object@cov.area[strat]/object@strata.area[strat])*100,2), "%", fill = T, sep = "")
cat("Strata area: ", object@strata.area[strat], fill = T)
cat("Number of samplers: ", object@samp.count[strat], fill = TRUE)
cat("Design angle: ", object@design.angle[strat], fill = TRUE)
cat("Edge protocol: ", object@edge.protocol[strat], fill = TRUE)
cat("Covered area: ", object@cov.area[strat], fill = TRUE)
cat("Strata coverage: ", round((object@cov.area[strat]/object@strata.area[strat])*100,2), "%", fill = TRUE, sep = "")
cat("Strata area: ", object@strata.area[strat], fill = TRUE)
}
#Now print totals
cat("\n Study Area Totals:", fill = T)
cat(" _________________", fill = T)
cat("Number of samplers: ", sum(object@samp.count, na.rm = T), fill = T)
cat("\n Study Area Totals:", fill = TRUE)
cat(" _________________", fill = TRUE)
cat("Number of samplers: ", sum(object@samp.count, na.rm = TRUE), fill = TRUE)
if(length(object@effort.allocation) > 0){
cat("Effort allocation: ", paste(object@effort.allocation*100, collapse = "%, "), "%", fill = T, sep = "")
cat("Effort allocation: ", paste(object@effort.allocation*100, collapse = "%, "), "%", fill = TRUE, sep = "")
}
cat("Covered area: ", sum(object@cov.area, na.rm = T), fill = T)
cat("Covered area: ", sum(object@cov.area, na.rm = TRUE), fill = TRUE)
index <- which(!is.na(object@cov.area))
cat("Average coverage: ", round((sum(object@cov.area[index])/sum(object@strata.area))*100,2), "%", fill = T, sep = "")
cat("Average coverage: ", round((sum(object@cov.area[index])/sum(object@strata.area))*100,2), "%", fill = TRUE, sep = "")
invisible(object)
}
)
6 changes: 3 additions & 3 deletions R/Region.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ setMethod(
if(!is.na(tmp)){
if(is.null(tmp$units)){
units <- units
warning("Coordinate reference system detected but no units can be found. Has this shape been projected - shapefiles must be projected on to a flat plane before surveys are designed. dssd is unstable and may generate errors when working with unprojected regions.", call. = FALSE, immediate. = TRUE)
warning("Coordinate reference system detected but no units can be found. Has this shape been projected - shapefiles must be projected on to a flat plane before surveys are designed. dssd is unstable and may generate errors when working with unprojected regions.", call. = FALSE)
}else
units <- tmp$units
}else{
Expand Down Expand Up @@ -137,7 +137,7 @@ setMethod(
definition=function(x, y, main = "", region.col = "default", strata = "all", line.col = gray(.2), legend.params = list()){
# Warn of depreications
if(length(legend.params) > 0){
warning("legend.params argument is deprecated since version 0.2.3", immediate. = TRUE, call. = FALSE)
warning("legend.params argument is deprecated since version 0.2.3", call. = FALSE)
}
# Tidy up space to keep ggplot happy
suppressWarnings(invisible(gc()))
Expand Down Expand Up @@ -213,7 +213,7 @@ setMethod(
definition=function(x, y, main = "", region.col = "default", strata = "all", line.col = gray(.2), col = "blue", lwd = 1, covered.area = FALSE, legend.params = list()){
# Warn of depreications
if(length(legend.params) > 0){
warning("legend.params argument is deprecated since version 0.2.3", immediate. = TRUE, call. = FALSE)
warning("legend.params argument is deprecated since version 0.2.3", call. = FALSE)
}
# Tidy up space to keep ggplot happy
suppressWarnings(invisible(gc()))
Expand Down
64 changes: 32 additions & 32 deletions R/Survey.Design.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,54 +148,54 @@ setMethod(
title <- paste("\n Strata ", strata.names[strat], ":", sep = "")
len.title <- nchar(title)
underline <- paste(" ", paste(rep("_", (len.title-3)), collapse = ""), sep = "")
cat(title, fill = T)
cat(underline, fill = T)
cat(title, fill = TRUE)
cat(underline, fill = TRUE)
design <- switch(object@design[strat],
"random" = "randomly located transects",
"systematic" = "systematically spaced transects",
"eszigzag" = "equal spaced zigzag",
"eszigzagcom" = "complementaty equal spaced zigzags",
"segmentedgrid" = "segmented grid")
cat("Design: ", design, fill = T)
cat("Design: ", design, fill = TRUE)
if(object@design[strat] %in% c("systematic", "eszigzag", "eszigzagcom", "segmentedgrid")){
cat("Spacing: ", object@spacing[strat], fill = T)
cat("Spacing: ", object@spacing[strat], fill = TRUE)
}
if(length(object@samplers) == 1){
cat("Number of samplers: ", object@samplers, " (shared across strata)", fill = T)
cat("Number of samplers: ", object@samplers, " (shared across strata)", fill = TRUE)
}else{
cat("Number of samplers: ", object@samplers[strat], fill = T)
cat("Number of samplers: ", object@samplers[strat], fill = TRUE)
}
line.length <- try(object@line.length, silent = TRUE)
if(!inherits(line.length, "try-error")){
if(length(line.length) == 1){
cat("Line length: ", line.length, " (shared across strata)", fill = T)
cat("Line length: ", line.length, " (shared across strata)", fill = TRUE)
}else if(length(line.length) == length(strata.names)){
cat("Line length: ", line.length[strat], fill = T)
cat("Line length: ", line.length[strat], fill = TRUE)
}else{
cat("Line length: NA", fill = T)
cat("Line length: NA", fill = TRUE)
}
}
if(object@design[strat] %in% c("segmentedgrid")){
cat("Segment length: ", object@seg.length[strat], fill = T)
cat("Segment threshold: ", object@seg.threshold[strat], fill = T)
cat("Segment length: ", object@seg.length[strat], fill = TRUE)
cat("Segment threshold: ", object@seg.threshold[strat], fill = TRUE)
}
cat("Design angle: ", object@design.angle[strat], fill = T)
cat("Edge protocol: ", object@edge.protocol[strat], fill = T)
cat("Design angle: ", object@design.angle[strat], fill = TRUE)
cat("Edge protocol: ", object@edge.protocol[strat], fill = TRUE)
}
dp <- ifelse(any(object@region@area < 10), 3, 0)
cat("\nStrata areas: ", paste(round(object@region@area, dp), collapse = ", "), fill = T)
cat("\nStrata areas: ", paste(round(object@region@area, dp), collapse = ", "), fill = TRUE)
if(length(object@region@units) > 0){
if(!inherits(line.length, "try-error")){
cat("Region and effort units: ", object@region@units, fill = T)
cat("Region and effort units: ", object@region@units, fill = TRUE)
}else{
cat("Region units: ", object@region@units, fill = T)
cat("Region units: ", object@region@units, fill = TRUE)
}
}
if(length(object@effort.allocation) > 0){
cat("Effort allocation across strata: ", paste(object@effort.allocation*100, collapse = "%, "), "%", sep = "", fill = T)
cat("Effort allocation across strata: ", paste(object@effort.allocation*100, collapse = "%, "), "%", sep = "", fill = TRUE)
}
if(length(object@coverage.scores) > 0){
cat("Coverage Simulation repetitions: ", object@coverage.reps, fill = T)
cat("Coverage Simulation repetitions: ", object@coverage.reps, fill = TRUE)
}

design.stats <- object@design.statistics
Expand All @@ -208,31 +208,31 @@ setMethod(
"line.length" = "Line length:",
"trackline" = "Trackline length:",
"cyclictrackline" = "Cyclic trackline length:")
cat("\n ", title, fill = T)
cat("\n ", title, fill = TRUE)
underline <- paste(rep("", (nchar(title)-3)), collapse = "")
cat(" ", underline, fill = T)
cat(" ", underline, fill = TRUE)
print(design.stats[[i]])
}
if(!all(is.na(object@coverage.scores))){
title <- "Coverage Score Summary:"
cat("\n ", title, fill = T)
cat("\n ", title, fill = TRUE)
underline <- paste(rep("", (nchar(title)-3)), collapse = "")
cat(" ", underline, fill = T)
cat(" ", underline, fill = TRUE)
cov.scores <- array(NA, dim = c(5, (length(strata.names)+1)), dimnames = list(c("Minimum", "Mean", "Median", "Maximum", "sd"), c(strata.names, "Total")))
for(i in seq(along = strata.names)){
cov.strat <- get.coverage(object, i)
cov.scores["Minimum",i] <- min(cov.strat, na.rm = T)
cov.scores["Mean",i] <- mean(cov.strat, na.rm = T)
cov.scores["Median",i] <- median(cov.strat, na.rm = T)
cov.scores["Maximum",i] <- max(cov.strat, na.rm = T)
cov.scores["sd",i] <- sd(cov.strat, na.rm = T)
cov.scores["Minimum",i] <- min(cov.strat, na.rm = TRUE)
cov.scores["Mean",i] <- mean(cov.strat, na.rm = TRUE)
cov.scores["Median",i] <- median(cov.strat, na.rm = TRUE)
cov.scores["Maximum",i] <- max(cov.strat, na.rm = TRUE)
cov.scores["sd",i] <- sd(cov.strat, na.rm = TRUE)
}
#Add in total column
cov.scores["Minimum","Total"] <- min(object@coverage.scores, na.rm = T)
cov.scores["Mean","Total"] <- mean(object@coverage.scores, na.rm = T)
cov.scores["Median","Total"] <- median(object@coverage.scores, na.rm = T)
cov.scores["Maximum","Total"] <- max(object@coverage.scores, na.rm = T)
cov.scores["sd","Total"] <- sd(object@coverage.scores, na.rm = T)
cov.scores["Minimum","Total"] <- min(object@coverage.scores, na.rm = TRUE)
cov.scores["Mean","Total"] <- mean(object@coverage.scores, na.rm = TRUE)
cov.scores["Median","Total"] <- median(object@coverage.scores, na.rm = TRUE)
cov.scores["Maximum","Total"] <- max(object@coverage.scores, na.rm = TRUE)
cov.scores["sd","Total"] <- sd(object@coverage.scores, na.rm = TRUE)
print(cov.scores)
}
}
Expand Down
Loading