-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d83d65
commit cadbfde
Showing
3 changed files
with
84 additions
and
0 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
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,67 @@ | ||
#' @title | ||
#' Checks setup of Pharmpy/pharmr | ||
#' | ||
#' @description | ||
#' Checks if everything is setup correctly. The following things are checked: | ||
#' * If Python is installed and has correct version | ||
#' * If Pharmpy is available | ||
#' * If Pharmpy and pharmr version matches | ||
#' | ||
#' @export | ||
check_setup <- function() { | ||
cli::cli_h3("Checking Python setup") | ||
py_okay <- check_python() | ||
if (py_okay) { | ||
cli::cli_h3("Checking Pharmpy and pharmr") | ||
pharmpy_okay <- check_pharmpy() | ||
} | ||
} | ||
|
||
check_python <- function() { | ||
py <- reticulate::py_discover_config() | ||
if (is.null(py)) { | ||
print_status('fail', 'No Python found') | ||
return(FALSE) | ||
} | ||
print_status('success', 'Python found:', additional_info=py$python) | ||
py_version <- as.character(py$version) | ||
if (utils::compareVersion(py_version, '3.11') == -1) { | ||
print_status('fail', 'Version not supported:', additional_info=py_version) | ||
return(FALSE) | ||
} | ||
print_status('success', 'Version supported:', additional_info=py_version) | ||
return(TRUE) | ||
} | ||
|
||
check_pharmpy <- function() { | ||
pharmpy_avail <- reticulate::py_module_available('pharmpy') | ||
if (isFALSE(pharmpy_avail)) { | ||
print_status('fail', 'Could not find Pharmpy installation') | ||
return(FALSE) | ||
} | ||
pharmpy_version <- reticulate::py_to_r(pharmpy$`__version__`) | ||
print_status('success', 'Pharmpy found:', additional_info=pharmpy_version) | ||
pharmr_version <- as.character(packageVersion('pharmr')) | ||
if (utils::compareVersion(pharmpy_version, pharmr_version) != 0) { | ||
print_status('fail', 'pharmr version does not match:', additional_info=pharmr_version) | ||
return(FALSE) | ||
} | ||
print_status('success', 'pharmr version matches:', additional_info=pharmr_version) | ||
return(TRUE) | ||
} | ||
|
||
print_status <- function(type, msg, additional_info=NULL) { | ||
if (type == 'success') { | ||
cli::cli_alert_success(msg) | ||
} | ||
else if (type == 'fail') { | ||
cli::cli_alert_danger(msg) | ||
} | ||
else { | ||
stop('Unknown status type') | ||
} | ||
if (!is.null(additional_info)) { | ||
cat(' ') | ||
cli::cli_alert(additional_info) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.