Open-Systems-Pharmacology / OSPSuite.RUtils

Utility functions for Open Systems Pharmacology R packages
https://www.open-systems-pharmacology.org/OSPSuite.RUtils/dev/
GNU General Public License v2.0
1 stars 3 forks source link

implement option validation function validateIsOption #141

Closed rengelke closed 6 months ago

rengelke commented 8 months ago
options <- list(
optimizationMethod = "genetic_algorithm",
includeInteractions = TRUE,
maxIterations = 1000L,
convergenceThreshold = 0.02
)

validOptions <- list(
optimizationMethod = list(
type = "character", allowedValues = c("gradient_descent", "genetic_algorithm")
),
includeInteractions = list(type = "logical"),
maxIterations = list(type = "integer", valueRange = c(1L, 10000L)),
convergenceThreshold = list(type = "numeric", valueRange = c(0, 1))
)
df <- data.frame(
  age = c(25L, 30L, NA),
  BMI = c(22.5, 27.3, 24.9),
  gender = c("M", "F", "F"),
  smoker = c(TRUE, FALSE, NA)
)

columnSpecs <- list(
  age = list(type = "integer", valueRange = c(18L, 65L), naAllowed = TRUE),
  BMI = list(type = "numeric", valueRange = c(15.0, 40.0), naAllowed = TRUE),
  gender = list(type = "character", allowedValues = c("M", "F"), naAllowed = TRUE),
  smoker = list(type = "logical", naAllowed = TRUE)
)

validateColumns(df, columnSpecs)
validateVector(x = 1:5, type = "integer")
validateVector(x = c(1.2, 2.5), type = "numeric", valueRange = c(1, 3))
validateVector(x = c("a", "b"), type = "character", allowedValues = c("a", "b", "c"))
validateVector(x = as.Date("2020-01-01"), type = "Date",
  valueRange = as.Date(c("2020-01-01", "2020-12-31")))
# Range validation examples
validateVectorRange(x = c(5, 10), type = "numeric", valueRange = c(1, 10))
validateVectorRange(x = c("a", "b"), type = "character", valueRange = c("a", "c"))
validateVectorRange(x = as.Date(c("2020-01-01")), type = "Date",
  valueRange = as.Date(c("2020-01-01", "2020-12-31")))
validateVectorRange(x = 1:3, type = "integer", valueRange = c(1L, 5L))

# Allowed values validation examples
validateVectorValues(x = c("a", "b"), type = "character", allowedValues = c("a", "b", "c"))
validateVectorValues(x = c(2L, 4L), type = "integer", allowedValues = c(1L, 2L, 3L, 4L))
validateVectorValues(x = c(TRUE), type = "logical", allowedValues = c(TRUE, FALSE))
PavelBal commented 8 months ago
codecov-commenter commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.69%. Comparing base (64bc87c) to head (7e38f91).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #141 +/- ## =========================================== + Coverage 99.53% 99.69% +0.15% =========================================== Files 18 20 +2 Lines 214 323 +109 =========================================== + Hits 213 322 +109 Misses 1 1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Felixmil commented 8 months ago

this function could be very useful to validate a whole dataframe column (or even dataframe)?. Would this work (i.e have vectors in inputOptions) ?

Also, did you take into account NULL or NAs ? Maybe allowing empty values could be an option in some cases ?

Yuri05 commented 8 months ago

it seems that Ubuntu18 runner images are not supported by GitHub anymore (that's why the 3 Ubuntu18 jobs are still pending) https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories

rengelke commented 8 months ago

this function could be very useful to validate a whole dataframe column (or even dataframe)?. Would this work (i.e have vectors in inputOptions) ?

Also, did you take into account NULL or NAs ? Maybe allowing empty values could be an option in some cases ?

Great idea about extending it to dataframes. It's totally doable with a few tweaks to make it more modular and flexible. We can definitely make it work for a column or dataframe.

About the NULL and NAs, I didn't focus much on them since we were validating options, where it wasn't so crucial. But including them makes a lot of sense for broader use.

I will get those changes done and commit..

PavelBal commented 7 months ago

@rengelke Whats the status of this one?