Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the DATRAS R package to support more flexible exchange-data downloads (optionally skipping CA/HL), modernizes some roxygen/package metadata, and replaces the deprecated multicore reference with parallel.
Changes:
- Add
download.hl,download.ca, andverbosearguments togetDatrasExchange()and adjust downstream handling for potentially missing components. - Update roxygen/package scaffolding (
"_PACKAGE") and minor Rd formatting/wording tweaks. - Replace
multicorewithparallelin docs/DESCRIPTION and update DESCRIPTION metadata (Encoding/RoxygenNote).
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
DATRAS/R/read_datras.R |
Adds new download/verbosity options and introduces NULL-handling changes across DATRASraw utilities. |
DATRAS/man/getDatrasExchange.Rd |
Documents new getDatrasExchange() arguments. |
DATRAS/man/predict.ALKmodel.Rd |
Updates mc.cores documentation to reference parallel. |
DATRAS/R/DATRAS.R |
Updates package-level roxygen to modern "_PACKAGE" pattern and whitespace tweaks. |
DATRAS/man/DATRAS-internal.Rd |
Minor whitespace adjustment. |
DATRAS/DESCRIPTION |
Replaces multicore with parallel, adds Encoding, updates RoxygenNote. |
Comments suppressed due to low confidence (1)
DATRAS/man/getDatrasExchange.Rd:36
- The new
download.hl/download.caarguments imply that the returnedDATRASrawmay haveHLand/orCAset toNULL. The current documentation doesn’t state this, which is important because several downstream helpers assume these components exist. Please document the resulting structure explicitly (e.g., which components may beNULLand what that means for subsequent operations).
\item{download.hl}{if FALSE, length frequency data in DATRAS ("HL") are
not downloaded. Default: TRUE}
\item{download.ca}{if FALSE, biological samples in DATRAS ("CA") are
not downloaded. Default: TRUE}
\item{verbose}{Print information? Default: TRUE}
}
\value{
DATRASraw object.
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (verbose) message("Downloading HH") | ||
| hh <- getDATRAS("HH", survey = survey, years = years, quarters = quarters) | ||
|
|
||
| if (download.hl) { | ||
| if (verbose) message("Downloading HL") | ||
| hl <- getDATRAS("HL", survey = survey, years = years, quarters = quarters) |
There was a problem hiding this comment.
The new verbose flag only gates the message("Downloading ...") calls. getDatrasExchange() still prints unconditionally via cat("Classes of the variables\n") / print(...) further down, so verbose = FALSE will still emit output. Wrap the remaining cat/print output (and any other informational output in this function) behind the same verbose flag to match the argument contract.
| if(is.null(ans) || nrow(ans)>0){ | ||
| ans[missingVariables] <- NA | ||
| } else { | ||
| for(ii in 1:length(missingVariables)) ans[,missingVariables[ii]] <- logical(0) |
There was a problem hiding this comment.
In c.DATRASraw(), addMissingVariables() now treats a missing component as NULL (ans <- x[[i]]) and then does ans[missingVariables] <- NA when ans is NULL. Subassignment on NULL will not produce a 0-row data.frame (it typically yields a plain list), which will break later Map(rbind, ...) expectations. If NULL components are now allowed, initialize ans to an explicit 0-row data.frame with the appropriate columns (and types where possible) before inserting missing variables.
| if(is.null(ans) || nrow(ans)>0){ | |
| ans[missingVariables] <- NA | |
| } else { | |
| for(ii in 1:length(missingVariables)) ans[,missingVariables[ii]] <- logical(0) | |
| if(is.null(ans)){ | |
| ans <- data.frame(row.names = integer(0)) | |
| } | |
| if(nrow(ans)>0){ | |
| ans[missingVariables] <- NA | |
| } else { | |
| for(ii in seq_along(missingVariables)) ans[,missingVariables[ii]] <- logical(0) |
|
|
||
| hh <- getDATRAS("HH", survey = survey, years = years, quarters = quarters) | ||
| if (verbose) message("Downloading HH") | ||
| hh <- getDATRAS("HH", survey = survey, years = years, quarters = quarters) |
There was a problem hiding this comment.
getDatrasExchange() now checks for getDATRAS() returning FALSE for CA/HL, but not for HH. If getDATRAS("HH", ...) fails and returns FALSE, the subsequent processing (e.g., renameDATRAS, addExtraVariables) will error in less clear ways. Add the same identical(hh, FALSE) handling as for CA/HL (ideally with a descriptive stop() message).
| hh <- getDATRAS("HH", survey = survey, years = years, quarters = quarters) | |
| hh <- getDATRAS("HH", survey = survey, years = years, quarters = quarters) | |
| if (identical(hh, FALSE)) { | |
| stop("Failed to download HH data from DATRAS for the requested survey, years, and quarters.") | |
| } |
| if (download.ca) { | ||
| if (verbose) message("Downloading CA") | ||
| ca <- getDATRAS("CA", survey = survey, years = years, quarters = quarters) | ||
| if (identical(ca, FALSE)) { | ||
| stop() | ||
| } | ||
| } else ca <- NULL | ||
|
|
There was a problem hiding this comment.
When download.ca = FALSE this function sets ca <- NULL (and leaves d[[1]] as NULL). Later in getDatrasExchange() the pipeline still calls fixMissingHaulIds(d, ...), but fixMissingHaulIds() unconditionally dereferences d[[1]]$haul.id, so download.ca = FALSE will currently crash. Skip fixMissingHaulIds() when CA is not present, or update fixMissingHaulIds() to return early when d[[1]] is NULL.
useful fixes that allow
CA,HLto beNULL, fix some roxygen and removed package issues, and new arguments allowing to download HH only.