-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: default idVariable and timeVariable methods using the respectiv…
…e options
- Loading branch information
Showing
6 changed files
with
70 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,5 +152,6 @@ Collate: | |
'random.R' | ||
'test.R' | ||
'timing.R' | ||
'variables.R' | ||
'verbose.R' | ||
'zzz.R' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#. idVariable #### | ||
#' @export | ||
#' @rdname idVariable | ||
#' @aliases idVariable,ANY-method | ||
setMethod('idVariable', 'ANY', function(object) getOption('latrend.id')) | ||
|
||
|
||
#. timeVariable #### | ||
#' @export | ||
#' @rdname timeVariable | ||
#' @aliases timeariable,ANY-method | ||
setMethod('timeVariable', 'ANY', function(object) getOption('latrend.time')) | ||
|
||
|
||
#' @title Guess the response variable | ||
#' @description | ||
#' Attempts to identify the response variable for the given trajectory data | ||
#' @param data A trajectories `data.frame`. | ||
#' @param id Id variable(s) to exclude. | ||
#' @param time Time variable(s) to exclude. | ||
#' @param cluster Cluster variable(s) to exclude. | ||
#' @keywords internal | ||
.guessResponseVariable = function( | ||
data, | ||
id = getOption('latrend.id'), | ||
time = getOption('latrend.time'), | ||
cluster = 'Cluster' | ||
) { | ||
assert_that( | ||
is.data.frame(data) | ||
) | ||
|
||
excludeColumns = unique(c(id, time, cluster)) | ||
|
||
numMask = vapply(data, is.numeric, FUN.VALUE = TRUE) | ||
numericColumns = names(data)[numMask] | ||
|
||
candidates = setdiff(numericColumns, excludeColumns) | ||
if (length(candidates) == 0L) { | ||
stop('unable to automatically determine the response variable. Specify the "response" argument.') | ||
} | ||
|
||
dfNum = subset(data, select = candidates) | ||
|
||
counts = vapply(dfNum, uniqueN, FUN.VALUE = 0L) | ||
response = names(dfNum)[which.max(counts)] | ||
|
||
message( | ||
sprintf( | ||
'Automatically selected "%s" as the response variable. | ||
To override this, specify the "response" argument.', | ||
response | ||
) | ||
) | ||
|
||
response | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.