Skip to content

Commit

Permalink
Merge branch 'devel' into 31_documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsi authored Feb 15, 2024
2 parents 2b3c6c8 + 9337ed5 commit eb08f30
Show file tree
Hide file tree
Showing 26 changed files with 3,040 additions and 301 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^vignettes/articles$
2 changes: 2 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:
branches: [ "main", "devel" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [main, devel]
workflow_dispatch:

env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ po/*~
rsconnect/
.Rproj.user
docs
inst/doc
4 changes: 4 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters: linters_with_defaults(
line_length_linter = line_length_linter(120),
object_usage_linter = NULL
)
7 changes: 6 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ Suggests:
callr,
httr2,
RPostgres,
pool,
testthat (>= 3.0.0),
usethis,
withr,
DBI,
glue,
jsonlite,
purrr
purrr,
knitr,
rmarkdown,
sentryR
RdMacros: mathjaxr
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
URL: https://ttscience.github.io/unbiased/
VignetteBuilder: knitr
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ ENV RENV_CONFIG_SANDBOX_ENABLED=FALSE

COPY ./renv ./renv
COPY .Rprofile .

# Both renv.lock and DESCRIPTION are needed to restore the R environment
COPY renv.lock .
COPY DESCRIPTION .

RUN R -e 'renv::restore()'

COPY .Rbuildignore .
COPY DESCRIPTION .
COPY NAMESPACE .
COPY inst/ ./inst
COPY R/ ./R
Expand Down
179 changes: 76 additions & 103 deletions R/api_create_study.R
Original file line number Diff line number Diff line change
@@ -1,139 +1,112 @@
api__minimization_pocock <- function( # nolint: cyclocomp_linter.
api__minimization_pocock <- function(
# nolint: cyclocomp_linter.
identifier, name, method, arms, covariates, p, req, res) {
validation_errors <- vector()
collection <- checkmate::makeAssertCollection()

err <- checkmate::check_character(name, min.chars = 1, max.chars = 255)
if (err != TRUE) {
validation_errors <- unbiased:::append_error(
validation_errors, "name", err
)
}
checkmate::assert(
checkmate::check_character(name, min.chars = 1, max.chars = 255),
.var.name = "name",
add = collection
)

err <- checkmate::check_character(identifier, min.chars = 1, max.chars = 12)
if (err != TRUE) {
validation_errors <- unbiased:::append_error(
validation_errors,
"identifier",
err
)
}
checkmate::assert(
checkmate::check_character(identifier, min.chars = 1, max.chars = 12),
.var.name = "identifier",
add = collection
)

err <- checkmate::check_choice(method, choices = c("range", "var", "sd"))
if (err != TRUE) {
validation_errors <- unbiased:::append_error(
validation_errors,
"method",
err
)
}
checkmate::assert(
checkmate::check_choice(method, choices = c("range", "var", "sd")),
.var.name = "method",
add = collection
)

err <-
checkmate::assert(
checkmate::check_list(
arms,
types = "integerish",
any.missing = FALSE,
min.len = 2,
names = "unique"
)
if (err != TRUE) {
validation_errors <- unbiased:::append_error(
validation_errors,
"arms",
err
)
}
),
.var.name = "arms",
add = collection
)

err <-
checkmate::assert(
checkmate::check_list(
covariates,
types = c("numeric", "list", "character"),
any.missing = FALSE,
min.len = 2,
min.len = 1,
names = "unique"
)
if (err != TRUE) {
validation_errors <-
unbiased:::append_error(validation_errors, "covariates", err)
}
),
.var.name = "covariates3",
add = collection
)

response <- list()
for (c_name in names(covariates)) {
c_content <- covariates[[c_name]]

err <- checkmate::check_list(
c_content,
any.missing = FALSE,
len = 2,
checkmate::assert(
checkmate::check_list(
c_content,
any.missing = FALSE,
len = 2,
),
.var.name = "covariates1",
add = collection
)
if (err != TRUE) {
validation_errors <-
unbiased:::append_error(
validation_errors,
glue::glue("covariates[{c_name}]"),
err
)
}
err <- checkmate::check_names(
names(c_content),
permutation.of = c("weight", "levels"),

checkmate::assert(
checkmate::check_names(
names(c_content),
permutation.of = c("weight", "levels"),
),
.var.name = "covariates2",
add = collection
)
if (err != TRUE) {
validation_errors <-
unbiased:::append_error(
validation_errors,
glue::glue("covariates[{c_name}]"),
err
)
}

# check covariate weight
err <- checkmate::check_numeric(c_content$weight,
lower = 0,
finite = TRUE,
len = 1,
null.ok = FALSE
checkmate::assert(
checkmate::check_numeric(c_content$weight,
lower = 0,
finite = TRUE,
len = 1,
null.ok = FALSE
),
.var.name = "weight",
add = collection
)
if (err != TRUE) {
validation_errors <-
unbiased:::append_error(
validation_errors,
glue::glue("covariates[{c_name}][weight]"),
err
)
}

err <- checkmate::check_character(c_content$levels,
min.chars = 1,
min.len = 2,
unique = TRUE

checkmate::assert(
checkmate::check_character(c_content$levels,
min.chars = 1,
min.len = 2,
unique = TRUE
),
.var.name = "levels",
add = collection
)
if (err != TRUE) {
validation_errors <-
unbiased:::append_error(
validation_errors,
glue::glue("covariates[{c_name}][levels]"),
err
)
}
}

# check probability
p <- as.numeric(p)
err <- checkmate::check_numeric(p, lower = 0, upper = 1, len = 1)
if (err != TRUE) {
validation_errors <-
unbiased:::append_error(
validation_errors,
"p",
err
)
}
checkmate::assert(
checkmate::check_numeric(p,
lower = 0, upper = 1, len = 1,
any.missing = FALSE, null.ok = FALSE
),
.var.name = "p",
add = collection
)


if (length(validation_errors) > 0) {
if (length(collection$getMessages()) > 0) {
res$status <- 400
return(list(
error = "Input validation failed",
validation_errors = validation_errors
error = "There was a problem with the input data to create the study",
validation_errors = collection$getMessages()
))
}

Expand Down Expand Up @@ -167,7 +140,7 @@ api__minimization_pocock <- function( # nolint: cyclocomp_linter.
if (!is.null(r$error)) {
res$status <- 503
return(list(
error = "There was a problem creating the study",
error = "There was a problem saving created study to the database",
details = r$error
))
}
Expand Down
Loading

0 comments on commit eb08f30

Please sign in to comment.