Skip to content

Issue1126 embedding ext function type - #1555

Merged
vincentvanhees merged 81 commits into
mainfrom
issue1126_embeddingExtFunctionType
Nov 8, 2026
Merged

vincentvanhees merged 81 commits into
mainfrom
issue1126_embeddingExtFunctionType

Conversation

@jhmigueles

@jhmigueles jhmigueles commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1126 => Implements support for external functions with reporttype = "type"

Fixes #1550 => Extends external function output handling to support multiple output columns, numeric/character output types, per-column aggregation functions, and independent type metrics in Part 5.

Checklist before merging:

  • Existing tests still work (check by running the test suite, e.g. from RStudio).
  • Added tests (if you added functionality) or fixed existing test (if you fixed a bug).
  • Clean code has been attempted, e.g. intuitive object names and no code redundancy.
  • Documentation updated:
    • Function documentation
    • Chapter vignettes for GitHub IO
    • Vignettes for CRAN
  • Corresponding issue tagged in PR message. If no issue exist, please create an issue and tag it.
  • Updated release notes in inst/NEWS.Rd with a user-readable summary. Please, include references to relevant issues or PR discussions.
  • If you think you made a significant contribution, add your name to the contributors lists in the DESCRIPTION, zenodo.json, and inst/CITATION files.
  • GGIR parameters were added/removed. If yes, please also complete checklist below.

If NEW GGIR parameter(s) were added then these NEW parameter(s) are:

  • documented in man/GGIR.Rd
  • included with a default in R/load_params.R
  • included with value class check in R/check_params.R
  • included in table of vignettes/GGIRParameters.Rmd with references to the GGIR parts the parameter is used in.
  • mentioned in NEWS.Rd as NEW parameter

If GGIR parameter(s) were deprecated these parameter(s) are:

  • documented as deprecated in man/GGIR.Rd
  • removed from R/load_params.R
  • removed from R/check_params.R
  • removed from table in vignettes/GGIRParameters.Rmd
  • mentioned as deprecated parameter in NEWS.Rd
  • added to the list in R/extract_params.R with deprecated parameters such that these do not produce warnings when found in old config.csv files.

jhmigueles and others added 30 commits June 11, 2024 13:11
…pe external function outcomes in part 2 reports
Merge branch 'master' into issue1126_embeddingExtFunctionType

# Conflicts:
#	R/g.analyse.perday.R
#	R/g.part2.R
Merge branch 'main' into issue1126_embeddingExtFunctionType

# Conflicts:
#	R/g.analyse.perday.R
#	R/g.part2.R
Merge branch 'main' into issue1126_embeddingExtFunctionType
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
…ll the type aggregation logic case insensitive
…ate code for extfuntype in new functions for part 5
…(both daysummary and personsummary in part 5)
Refactorize each categorical output column independently using its own
factor levels, and add a regression test covering multiple type outputs.
LevelsExternalFunction was overwritten for every processed block, causing
the complete recording to be factorized using only levels observed in the
final block. Consequently, categories present in earlier blocks but absent
from the final block were converted to NA.

Accumulate levels across all blocks and add regression coverage for
multiple categorical outputs.
Returned timestamps were separated before external-function outputs were
aggregated or repeated, then added back unchanged. When outputres differed
from the GGIR epoch size, timestamps and output values therefore had
different lengths, allowing R to silently recycle values and produce
misaligned results.

Retain the starting timestamp when aggregating into GGIR epochs, and
generate timestamps at GGIR epoch intervals when repeating lower-resolution
outputs. Add regression tests for both resolution-conversion directions.
check_myfun accepts a single outputtype or reporttype for external
functions with multiple output columns, but downstream code indexed these
values as if one had been provided per column. Columns after the first
therefore received NA or were skipped, potentially causing errors in part
2 and incomplete type processing and reporting in part 5.

Recycle scalar outputtype and reporttype values to match the number of
external output columns before column-specific processing. Add regression
coverage confirming that a scalar reporttype applies to multiple
categorical columns.
Remove Tnames from the documented return values because identify_levels
does not return it, and document the threshold element that is returned.
vincentvanhees and others added 16 commits October 9, 2026 19:57
Add regression coverage confirming that vector-valued reporttype settings
retain their per-column mapping while scalar values continue to be
recycled across all external function output columns.
…pe_edits_Vincent

Edits to PR 1555: Fix multi-column external function handling and timestamp alignment
…racter vectors or mixed numeric/character matrices, relax aggfunction check, and update tests
…Type to avoid innecessary calculations as total steps during acceleration levels in a type external function metric
Preserve all-NA groups when aggregating external function output to avoid
shifting subsequent epochs. Default missing reporttype values to scalar in
per-day analysis for compatibility with legacy myfun configurations.

Add regression coverage for both cases.
Exclude invalid epochs from Part 5 type durations and prevent unknown
padded epochs from affecting invalid or unclassified totals. Preserve
scalar recording summaries in mixed type/scalar configurations, restore
factor levels after day padding, and match external metadata by column
name after imputation reorders mixed outputs.

Add regression coverage for invalid epochs, partial-day padding, and
mixed external outputs.
Reset ndayswindow when switching to data masking strategy 1 so the reused configuration does not trigger duplicate parameter warnings.
Correct Part 5 type-column ordering, add regression coverage, and align external-function documentation with aggregation behavior, return structures, compatibility defaults, and generated reports.
- In identify_levels_ExtFunType(), make competing type-bout
  assignments mutually exclusive by treating previously assigned epochs
  as hard bout boundaries.

- In identify_levels_ExtFunType(), preserve the original spelling and
  case of categorical levels while matching tbout.order
  case-insensitively.

- In identify_levels_ExtFunType(), g.report.part5(), and
  visualReport(), replace dynamically constructed regular expressions
  with literal column-name matching so names containing regex
  characters are handled correctly.

- In g.part5_analyseSegment_ExtFunType(), use the level names stored by
  identify_levels_ExtFunType() when generating type-bout variables.

- In aggregateEvent(), detectEventBouts(), and g.analyse.perday(),
  disambiguate summary and bout variable names when myfun returns
  multiple event outputs by including the corresponding event metric
  name. Preserve the existing names for single-event configurations.

- In check_myfun(), reject duplicate myfun$colnames because duplicate
  outputs cannot be mapped reliably to per-column report settings.

- In ExternalFunctionType.Rmd, clarify that CSV reports include all
  categorical outputs, while visualReport() currently plots only the
  first output configured with reporttype = "type".

- In ExternalFunction.Rmd and identify_levels_ExtFunType.Rd, document
  multiple-event naming and case-preserving categorical-level behavior.

- Add regression tests for competing type bouts, case-distinct levels,
  special characters in names, duplicate output names, and multiple
  event outputs.
Fix external function aggregation, type summaries, and mixed-output reporting

@vincentvanhees vincentvanhees left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My main concern is overlap between ExternalFunction.Rmd and ExternalFunctionType.Rmd, where both now discuss the same topics. See comments below.

I think it would be good to have all basic functionality for external functon embedding discussed in ExternalFunction.Rmd, including aggregation and missing data handling. In that way other vignettes can focus more on the practical use-cases without having to discuss those details again.

For example StepCadenceAnalysis.Rmd shows a specific example of event classifiers and how to interpret their output, but does not list all the parameters again that were discussed in ExternalFunction.Rmd.

Similarly, ExternalFunctionType.Rmd could showcase examples of activity type classifiers and the output this generates.

Comment thread vignettes/ExternalFunctionType.Rmd Resolved
Comment thread vignettes/ExternalFunctionType.Rmd Resolved
Comment thread vignettes/ExternalFunctionType.Rmd Resolved
…tion about integration of output in part 5 and in the visual report
@jhmigueles

Copy link
Copy Markdown
Collaborator Author

Thanks @vincentvanhees, I've implemented your feedback, and additionally expanded the section # Integration in GGIR output in ExternalFunction.Rmd with the integration of the output in part 5 and in the visual report.

Explain that all-missing epochs are retained but their aggregated values
depend on aggfunction. Format report filename templates as inline code
and describe the day window as time outside the sustained sleep period.
@vincentvanhees
vincentvanhees merged commit 8e72463 into main Nov 8, 2026
7 checks passed
@vincentvanhees
vincentvanhees deleted the issue1126_embeddingExtFunctionType branch November 8, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants