Skip to content

Commit 9cb8651

Browse files
committed
Minor updates to silence some annoying warnings
1 parent bbee85d commit 9cb8651

7 files changed

Lines changed: 33 additions & 12 deletions

File tree

R/predict.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#' extraction before making model predictions.
77
#'
88
#' @param input Path to a CSV. See Details.
9+
#' @param quiet Logical. Set to `TRUE` to suppress messages. Default is `FALSE`.
910
#'
1011
#' @details
1112
#' The input for this function should be a path to aCSV with the following
@@ -29,11 +30,11 @@
2930
#' @import glmnet parsnip recipes workflows vetiver readr
3031
#'
3132
#' @export
32-
predict_integral_radiomics <- function(input) {
33-
df <- process_input_csv(input)
33+
predict_integral_radiomics <- function(input, quiet = FALSE) {
34+
df <- process_input_csv(input, quiet)
3435

3536
feats <-
36-
purrr::map2(df$image, df$mask, extract_radiomics) |>
37+
purrr::map2(df$image, df$mask, extract_radiomics, .progress = !quiet) |>
3738
purrr::list_rbind()
3839

3940
pred_df <- dplyr::bind_cols(df, feats)
@@ -46,7 +47,12 @@ predict_integral_radiomics <- function(input) {
4647
pred <- stats::predict(model, new_data = pred_df, type = "prob")
4748

4849
dplyr::bind_cols(df, pred) |>
49-
dplyr::select(-c(study, pid, nid))
50+
dplyr::select(-c(study, pid, nid)) |>
51+
dplyr::rename_with(\(x) stringr::str_remove(x, "^epi_")) |>
52+
dplyr::rename(
53+
pred_benign = .pred_0,
54+
pred_malignant = .pred_1
55+
)
5056
}
5157

52-
utils::globalVariables(c("study", "pid", "nid"))
58+
utils::globalVariables(c("study", "pid", "nid", ".pred_0", ".pred_1"))

R/process_input_csv.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
process_input_csv <- function(input) {
2-
df <- readr::read_csv(input)
1+
process_input_csv <- function(input, quiet) {
2+
df <- readr::read_csv(input, show_col_types = !quiet, progress = !quiet)
33

44
image <- check_files_exist(df$image, "`image`")
55
mask <- check_files_exist(df$mask, "`mask`")

R/radiomics-extraction.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
#'
33
#' @param image File path to input image.
44
#' @param mask File path to nodule mask.
5+
#' @param quiet Logical. Set to `TRUE` to suppress messages. Default is `FALSE`.
56
#'
67
#' @export
7-
extract_radiomics <- function(image, mask) {
8+
extract_radiomics <- function(image, mask, quiet = FALSE) {
89
params <- system.file("PyRadiomics_config.yaml", package = "integralrad")
910
extractor <- radiomics$featureextractor$RadiomicsFeatureExtractor(params)
11+
12+
logger <- logging$getLogger("radiomics.glcm")
13+
logger$setLevel(logging$ERROR)
14+
1015
result <- extractor$execute(image, mask)
16+
1117
names_to_remove <- stringr::str_detect(names(result), "^diagnostics_")
1218
results_tbl <- dplyr::as_tibble(result[!names_to_remove])
1319
results_tbl

R/zzz.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
radiomics <- NULL
2+
logging <- NULL
23

34
.onLoad <- function(libname, pkgname) {
45
Sys.setenv(RETICULATE_PYTHON = "managed")
@@ -9,6 +10,6 @@ radiomics <- NULL
910
"trimesh==3.23.5"
1011
)
1112
)
12-
13+
logging <<- reticulate::import("logging", delay_load = TRUE)
1314
radiomics <<- reticulate::import("radiomics", delay_load = TRUE)
1415
}

exec/INTEGRAL-Radiomics.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ input <- NA
1616
#| negative_alias: false
1717
output <- NA
1818

19-
df_pred <- integralrad::predict_integral_radiomics(input)
19+
#| description: Suppress messages.
20+
#| negative_alias: false
21+
quiet <- FALSE
22+
23+
df_pred <- integralrad::predict_integral_radiomics(input, quiet)
2024

2125
readr::write_csv(df_pred, output)

man/extract_radiomics.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/predict_integral_radiomics.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)