Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tsrobinson committed Aug 16, 2023
2 parents dbb37fc + d9f8525 commit 31b833f
Show file tree
Hide file tree
Showing 24 changed files with 61,109 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check
name: R-CMD-check-Linux

jobs:
R-CMD-check:
Expand All @@ -27,4 +25,3 @@ jobs:
needs: check

- uses: r-lib/actions/check-r-package@v2

31 changes: 31 additions & 0 deletions .github/workflows/testmacos.yml
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
31 changes: 31 additions & 0 deletions .github/workflows/testwindows.yml
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
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
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
15 changes: 4 additions & 11 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@ Description: A tool for multiply imputing missing data using 'MIDAS', a deep lea
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Depends:
R (>= 3.6.0),
data.table,
mltools,
reticulate
Imports:
Suggests:
testthat,
knitr,
rmarkdown
SystemRequirements: Python (>= 3.7.0)
Depends: R (>= 3.6.0), data.table, mltools, reticulate
Imports: rappdirs
Suggests: testthat, knitr, rmarkdown
SystemRequirements: Python (>= 3.6.0)
VignetteBuilder: knitr
License: Apache License (>= 2.0)
URL: https://github.com/MIDASverse/rMIDAS
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ export(col_minmax)
export(combine)
export(complete)
export(convert)
export(delete_rMIDAS_env)
export(midas_setup)
export(na_to_nan)
export(overimpute)
export(reset_rMIDAS_env)
export(set_python_env)
export(train)
export(undo_minmax)
Expand Down
11 changes: 7 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# rMIDAS 0.4

## v0.4.2
* Added headless functionality to `matplotlib` calls in Python
* Updated conda setup file
* Minor updates to underlying Python code to address deprecation issues

* rMIDAS now includes an automatic setup that prompts the user on whether to automatically set up a Python environment and its dependencies
* Addressed dependency issues and deprecation warnings (rather a Python update than R)
* An additional .Rmd example that showcases rMIDAS core functionalities
* Added a new vignette for running rMIDAS in headless mode, along with updates to the existing vignettes
* Updated the accompanying YAML environment file that works on all major operating systems (including macOS running Apple silicon hardware)
* Expanded our GitHub Actions workflow to also perform R-CMD-checks on macOS and Windows systems
* Updated README file

## v0.4.1
* Disabled Tensorflow deprecation warnings as default (as Python rather than R warning)
Expand Down
40 changes: 40 additions & 0 deletions R/delete_env.R
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.")
}
32 changes: 32 additions & 0 deletions R/reset_env.R
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.")
}
100 changes: 96 additions & 4 deletions R/zzz.R
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
}
Loading

0 comments on commit 31b833f

Please sign in to comment.