Skip to content

Extra stuff#28

Open
tokami wants to merge 5 commits intoDTUAqua:masterfrom
tokami:extra_stuff
Open

Extra stuff#28
tokami wants to merge 5 commits intoDTUAqua:masterfrom
tokami:extra_stuff

Conversation

@tokami
Copy link
Copy Markdown
Member

@tokami tokami commented Apr 23, 2026

useful fixes that allow CA, HL to be NULL, fix some roxygen and removed package issues, and new arguments allowing to download HH only.

Copilot AI review requested due to automatic review settings April 23, 2026 13:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and verbose arguments to getDatrasExchange() and adjust downstream handling for potentially missing components.
  • Update roxygen/package scaffolding ("_PACKAGE") and minor Rd formatting/wording tweaks.
  • Replace multicore with parallel in 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.ca arguments imply that the returned DATRASraw may have HL and/or CA set to NULL. 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 be NULL and 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.

Comment thread DATRAS/R/read_datras.R
Comment on lines +32 to 37
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)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread DATRAS/R/read_datras.R
Comment on lines +426 to 429
if(is.null(ans) || nrow(ans)>0){
ans[missingVariables] <- NA
} else {
for(ii in 1:length(missingVariables)) ans[,missingVariables[ii]] <- logical(0)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
Comment thread DATRAS/R/read_datras.R

hh <- getDATRAS("HH", survey = survey, years = years, quarters = quarters)
if (verbose) message("Downloading HH")
hh <- getDATRAS("HH", survey = survey, years = years, quarters = quarters)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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.")
}

Copilot uses AI. Check for mistakes.
Comment thread DATRAS/R/read_datras.R
Comment on lines +24 to 31
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

Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants