Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get required #159

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions R/getRequiredParams.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#' @title Return all required params in a param set.
#'
#' @description
#' Returns all params which are required by the given [\code{\link{ParamSet}}].
#' If no parameter is required in the param set an empty param set is returned.
#'
#' @template arg_parset
#' @return par.set [\code{\link{ParamSet}}]\cr
#' Parameter set.
#' @export
getRequiredParams = function(par.set) {
reqs = getRequirements(par.set)
# find all parameters that are in require in the param set at least once
all.reqs = unique(unlist(lapply(reqs, all.vars)))
# remove required parameters that are not in the par.set
all.reqs = intersect(getParamIds(par.set), all.reqs)

# if no parameters are in require return an empty parameter set
if (is.null(all.reqs))
makeParamSet()
else
filterParams(par.set, ids = all.reqs)
}