-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
24 changed files
with
61,109 additions
and
92 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,31 @@ | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
name: R-CMD-check-macOS | ||
|
||
jobs: | ||
R-CMD-check: | ||
runs-on: macos-latest | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
R_KEEP_PKG_SOURCE: yes | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
use-public-rspm: true | ||
|
||
- name: Install pandoc | ||
run: | | ||
brew install pandoc | ||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
extra-packages: any::rcmdcheck | ||
needs: check | ||
|
||
- uses: r-lib/actions/check-r-package@v2 |
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,31 @@ | ||
on: | ||
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
name: R-CMD-check-Windows | ||
|
||
jobs: | ||
R-CMD-check: | ||
runs-on: windows-latest | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
R_KEEP_PKG_SOURCE: yes | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: r-lib/actions/setup-r@v2 | ||
with: | ||
use-public-rspm: true | ||
|
||
- name: Install pandoc | ||
run: | | ||
choco install pandoc | ||
- uses: r-lib/actions/setup-r-dependencies@v2 | ||
with: | ||
extra-packages: any::rcmdcheck | ||
needs: check | ||
|
||
- uses: r-lib/actions/check-r-package@v2 |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Version: 0.4.1 | ||
Date: 2022-06-20 15:10:41 UTC | ||
SHA: 61874a14cb52c2d7f9db9d7d8378a461fe5449fe | ||
Version: 0.4.2 | ||
Date: 2023-06-13 21:47:39 UTC | ||
SHA: dbb37fc9fbd2b8967539138aa9e27ae33c270705 |
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
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,40 @@ | ||
#' Delete the rMIDAS Environment and Configuration | ||
#' | ||
#' Deletes both the virtual environment and the configuration file for the rMIDAS package. | ||
#' After deletion, it is necessary to restart the R session and then load the rMIDAS package once more. | ||
#' This will trigger the setup process again. | ||
#' | ||
#' @name delete_rMIDAS_env | ||
#' @aliases delete_rMIDAS_env | ||
#' @return A message indicating the completion of the deletion process. | ||
#' @export | ||
|
||
delete_rMIDAS_env <- function() { | ||
|
||
if (requireNamespace("rappdirs", quietly = TRUE)) { | ||
config_dir <- rappdirs::user_config_dir(appname = "rMIDAS") | ||
config_file <- file.path(config_dir, ".rMIDAS_config") | ||
|
||
virtual_env_dir <- rappdirs::user_data_dir(appname = "rMIDAS") | ||
virtual_env_name <- file.path(virtual_env_dir, "rMIDAS_env_auto_setup") | ||
|
||
} else { | ||
stop("The 'rappdirs' package is required to determine the directories. Please install it.") | ||
} | ||
|
||
if (dir.exists(virtual_env_name)) { | ||
unlink(virtual_env_name, recursive = TRUE) | ||
message("rMIDAS virtual environment deleted successfully.") | ||
} else { | ||
message("rMIDAS virtual environment not found.") | ||
} | ||
|
||
if (file.exists(config_file)) { | ||
file.remove(config_file) | ||
message("rMIDAS configuration file deleted successfully.") | ||
} else { | ||
message("rMIDAS configuration file not found.") | ||
} | ||
|
||
message("Please restart the R session and then load rMIDAS to set up the environment again.") | ||
} |
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,32 @@ | ||
#' Reset the rMIDAS Environment Configuration | ||
#' | ||
#' Resets the configuration for the rMIDAS package by deleting the configuration file. | ||
#' Once the configuration is reset, it is necessary to restart the R session | ||
#' and then load the rMIDAS package once more. | ||
#' | ||
#' @name reset_rMIDAS_env | ||
#' @aliases reset_rMIDAS_env | ||
#' @return A message indicating the completion of the reset process. | ||
#' @export | ||
|
||
reset_rMIDAS_env <- function() { | ||
# Use rappdirs to get the appropriate user configuration directory | ||
if (requireNamespace("rappdirs", quietly = TRUE)) { | ||
config_dir <- rappdirs::user_config_dir(appname = "rMIDAS") | ||
config_file <- file.path(config_dir, ".rMIDAS_config") | ||
} else { | ||
stop("The 'rappdirs' package is required to determine the configuration directory. Please install it.") | ||
} | ||
|
||
if (!file.exists(config_file)) { | ||
stop("rMIDAS config file doesn't exist.") | ||
} | ||
|
||
# Option 1: Delete the entire config file. | ||
file.remove(config_file) | ||
|
||
# OR Option 2: Overwrite the config file with a default or empty value. | ||
# writeLines("", con = config_file) | ||
|
||
message("rMIDAS configuration reset. Please restart the R session and then load rMIDAS again.") | ||
} |
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 |
---|---|---|
@@ -1,17 +1,109 @@ | ||
.onLoad <- function(libname, pkgname) { | ||
|
||
options("python_custom" = NULL) | ||
options("python_initialised" = NULL) | ||
|
||
|
||
if (requireNamespace("rappdirs", quietly = TRUE)) { | ||
config_dir <- rappdirs::user_config_dir(appname = "rMIDAS") | ||
if (!dir.exists(config_dir)) { | ||
dir.create(config_dir, recursive = TRUE) | ||
} | ||
config_file <- file.path(config_dir, ".rMIDAS_config") | ||
|
||
virtual_env_dir <- rappdirs::user_data_dir(appname = "rMIDAS") | ||
if (!dir.exists(virtual_env_dir)) { | ||
dir.create(virtual_env_dir, recursive = TRUE) | ||
} | ||
} else { | ||
stop("The 'rappdirs' package is required for rMIDAS. Please install it.") | ||
} | ||
|
||
if (!file.exists(config_file)) { | ||
if (!interactive()) { | ||
user_input <- "n" | ||
packageStartupMessage("rMIDAS is loaded. In headless mode its environment and dependencies need to be set up manually. Please read https://github.com/MIDASverse/rMIDAS for additional help on how to set up and configure your environment.") | ||
packageStartupMessage("If you want to change your Python environment use 'reset_rMIDAS_env()' to reset your configuration. After resetting, you'll need to restart the R session and run 'library(rMIDAS)' again.") | ||
} else { | ||
user_input <- readline("Do you want rMIDAS to automatically set up a Python environment and its dependencies? Enter 'y' for Yes, or any other key for No : \n") | ||
writeLines(user_input, con = config_file) | ||
if(tolower(user_input) != "y") {packageStartupMessage("rMIDAS is loaded but its environment and dependencies are not set up automatically. Please read https://github.com/MIDASverse/rMIDAS for additional help on how to set up and configure your environment.")} | ||
if(tolower(user_input) == "y") {packageStartupMessage("rMIDAS is being set up automatically.")} | ||
} | ||
} else { | ||
user_input <- readLines(con = config_file)[1] | ||
if(tolower(user_input) != "y") { | ||
packageStartupMessage("\n \n","rMIDAS is loaded. Please read https://github.com/MIDASverse/rMIDAS for additional help on how to set up and configure your environment. If you want to use a different Python environment use 'reset_rMIDAS_env()' to reset the your configuration. After resetting, you'll need to restart the R session and run 'library(rMIDAS)' again.\n") | ||
writeLines(user_input, con = config_file) | ||
} | ||
} | ||
|
||
if (tolower(user_input) == "y") { | ||
Sys.setenv(WORKON_HOME = virtual_env_dir) | ||
virtual_env_name <- "rMIDAS_env_auto_setup" | ||
if (virtual_env_name %in% reticulate::virtualenv_list()) { | ||
reticulate::use_virtualenv(virtual_env_name, required = TRUE) | ||
} else { | ||
current_version <- reticulate::py_discover_config()$version | ||
matched_version <- NULL | ||
if (grepl("^3\\.(6|7|8|9|10).*|^3\\.(6|7|8|9|10)-dev$", current_version)) { | ||
matched_version <- current_version | ||
} else { | ||
matched_version <- "3.8.17" | ||
reticulate::install_python(version = matched_version, force = TRUE) | ||
} | ||
reticulate::virtualenv_create(envname = virtual_env_name, python_version = matched_version) | ||
reticulate::use_virtualenv(virtual_env_name, required = TRUE) | ||
python_version <- reticulate::py_discover_config()$version | ||
version_components <- strsplit(python_version, "\\.")[[1]] | ||
python_version_major <- as.numeric(version_components[1]) | ||
python_version_minor <- as.numeric(version_components[2]) | ||
|
||
requirements_txt <- "numpy>=1.5 | ||
scikit-learn | ||
matplotlib | ||
pandas>=0.19 | ||
tensorflow_addons<0.20.0 | ||
statsmodels | ||
scipy | ||
" | ||
|
||
if (python_version_major == 3 && as.integer(python_version_minor) >= 8 && as.integer(python_version_minor) < 11) { | ||
if (Sys.info()["sysname"] == "Darwin" && Sys.info()["machine"] == "arm64") { | ||
requirements_txt <- paste0(requirements_txt, "tensorflow-macos<2.12.0") | ||
} else { | ||
requirements_txt <- paste0(requirements_txt, "tensorflow<2.12.0") | ||
} | ||
} else { | ||
if (Sys.info()["sysname"] == "Darwin" && Sys.info()["machine"] == "arm64") { | ||
requirements_txt <- paste0(requirements_txt, "tensorflow-macos>=1.10") | ||
} else { | ||
requirements_txt <- paste0(requirements_txt, "tensorflow>=1.10") | ||
} | ||
} | ||
|
||
requirements_file <- tempfile(fileext = ".txt") | ||
writeLines(requirements_txt, requirements_file) | ||
|
||
reticulate::py_install(envname = virtual_env_name, pip = TRUE, packages = c("-r", requirements_file)) | ||
reticulate::py_config() | ||
reticulate::use_virtualenv(virtual_env_name, required = TRUE) | ||
packageStartupMessage("rMIDAS has been automatically set up.") | ||
#.rs.restartR() | ||
} | ||
packageStartupMessage("rMIDAS is loaded. Please read https://github.com/MIDASverse/rMIDAS for additional help on how to set up and configure your environment. If you want to change your Python environment use 'reset_rMIDAS_env()' to reset your configuration. After resetting, you'll need to restart the R session and run 'library(rMIDAS)' again.") | ||
} | ||
} | ||
|
||
.onAttach <- function(libname, pkgname) { | ||
|
||
packageStartupMessage("\n## \n", | ||
"## rMIDAS: Multiple Imputation using Denoising Autoencoders \n", | ||
"## Authors: Thomas Robinson and Ranjit Lall \n", | ||
"## Please visit https://github.com/MIDASverse/rMIDAS for more information \n", | ||
"## \n" | ||
) | ||
|
||
} | ||
|
||
.onDetach <- function(libpath) { | ||
# Nothing | ||
} |
Oops, something went wrong.