Skip to content

Commit

Permalink
version 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tsrobinson authored and cran-robot committed Aug 23, 2023
1 parent d28dbca commit 9acf8fa
Show file tree
Hide file tree
Showing 21 changed files with 854 additions and 140 deletions.
18 changes: 11 additions & 7 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: rMIDAS
Title: Multiple Imputation with Denoising Autoencoders
Version: 0.4.2
Version: 0.5.0
Authors@R: c(
person(given = "Thomas",
family = "Robinson",
Expand All @@ -14,25 +14,29 @@ Authors@R: c(
comment = c(ORCID = "0000-0003-1455-3506")),
person(given = "Alex",
family = "Stenlake",
role = c("ctb","cph"))
role = c("ctb","cph")),
person(given = "Elviss",
family = "Dvinskis",
role = c("ctb"))
)
Description: A tool for multiply imputing missing data using 'MIDAS', a deep learning method based on denoising autoencoder neural networks. This algorithm offers significant accuracy and efficiency advantages over other multiple imputation strategies, particularly when applied to large datasets with complex features. Alongside interfacing with 'Python' to run the core algorithm, this package contains functions for processing data before and after model training, running imputation model diagnostics, generating multiple completed datasets, and estimating regression models on these datasets.
Encoding: UTF-8
RoxygenNote: 7.2.3
Depends: R (>= 3.6.0), data.table, mltools, reticulate
Imports:
Imports: rappdirs
Suggests: testthat, knitr, rmarkdown
SystemRequirements: Python (>= 3.7.0)
SystemRequirements: Python (>= 3.6.0)
VignetteBuilder: knitr
License: Apache License (>= 2.0)
URL: https://github.com/MIDASverse/rMIDAS
BugReports: https://github.com/MIDASverse/rMIDAS/issues
NeedsCompilation: no
Packaged: 2023-06-13 21:47:33 UTC; tsr
Packaged: 2023-08-23 19:00:45 UTC; tsr
Author: Thomas Robinson [aut, cre, cph]
(<https://orcid.org/0000-0001-7097-1599>),
Ranjit Lall [aut, cph] (<https://orcid.org/0000-0003-1455-3506>),
Alex Stenlake [ctb, cph]
Alex Stenlake [ctb, cph],
Elviss Dvinskis [ctb]
Maintainer: Thomas Robinson <ts.robinson1994@gmail.com>
Repository: CRAN
Date/Publication: 2023-06-13 22:00:02 UTC
Date/Publication: 2023-08-23 19:20:02 UTC
33 changes: 20 additions & 13 deletions MD5
@@ -1,21 +1,23 @@
d1742e7e3583de68f82f6507e434be92 *DESCRIPTION
4b0e8158ffc6dfd349c09ae2cf78bf79 *NAMESPACE
fd24c66248cb748de5af921236f257ba *NEWS.md
caa4683986dd6ba5127f2c21ad9d60b9 *DESCRIPTION
c0ad4e84355575060616343a33b05e30 *NAMESPACE
cb0f7a72e92f80da41213ab9b5016cfe *NEWS.md
ef0003da87b27296ac06e74c41ead245 *R/delete_env.R
6e0cd17aed32c0311fe76f2996c70530 *R/load_utils.R
1a270d66e86b94acd370e17b68e1e42a *R/midas_functions.R
58f51f0d43076486ac2a81350f2d5733 *R/pre_processing.R
ee40f3a6afb6ceecc9c15bf746398cd3 *R/reset_env.R
0ef1815140875b09e36db14da6177157 *R/rubin_analysis.R
dad62e621f64cde04f7fd3146db0a8a0 *R/setup.R
becdf5098e1c9a18c9bfc31688df0dd0 *R/zzz.R
b9c9c517bd30adb0e332eac0c5bfda07 *README.md
3dc6b54a3cffa42713b8db1b9fa0d667 *R/zzz.R
93b6aa4d30f83d1ebf15be6318258d79 *README.md
aa1b5f639b7faf40878ba1ddc354f663 *build/vignette.rds
d49090aff7e7d8f2614da7cfcc8dda64 *inst/CITATION
69815d9858673c275fd3251958343e93 *inst/doc/custom_python_versions.R
0c307d22142c8b940bb2eabf7a171f66 *inst/doc/custom_python_versions.Rmd
080764a0d25f92a64c151acb3e3ee5a1 *inst/doc/custom_python_versions.html
072b1f5c9f87b73195cf00bb70bbd106 *inst/doc/imputation_demo.R
8fb23fc2e93eee5bb937a21099ca4563 *inst/doc/imputation_demo.Rmd
68895f69946598ef5d6d409eb673e09a *inst/doc/imputation_demo.html
15293a185fbfa5da55b7bb0b8a1ce8c7 *inst/doc/custom_python_versions.R
c76d8adb11b29e50e59045f93bc2e908 *inst/doc/custom_python_versions.Rmd
ae068b4b44b97be3a82db95860ba10d2 *inst/doc/custom_python_versions.html
b88b42aefd74a8d9416f19a419d8b388 *inst/doc/imputation_demo.R
04d83b9a9a4b7ff88610d4ea2a006b13 *inst/doc/imputation_demo.Rmd
02c1a8cfc0b906356bace8f42a572c88 *inst/doc/imputation_demo.html
3bd22cc9c76f48dde7e3559e64165b67 *inst/doc/use-server.R
ae13282efbb233718090fd8323aad0e0 *inst/doc/use-server.Rmd
345dc5c0bbb3d60575f4af32572f4871 *inst/doc/use-server.html
Expand All @@ -33,6 +35,7 @@ c13c5d8b933d5dd21459c139ebf43538 *man/col_minmax.Rd
2bb86f17a81bf892ae7e2b191f6f95fe *man/combine.Rd
a221670d70dff3414cac42094b0a80f5 *man/complete.Rd
48413a5a794caa38137a9bc36ca02c4c *man/convert.Rd
83a067cc99d71534e1db4023ae2b5a96 *man/delete_rMIDAS_env.Rd
ee448b97e60bee367e6e5f98ba823b16 *man/figures/logo.png
551e6d455d913ad82f2885625e08708b *man/figures/logos.drawio
0029cb10bab1c771f84aa1892f749efd *man/import_midas.Rd
Expand All @@ -42,13 +45,17 @@ a796458731eabf8e9e6bc35b2d828cf0 *man/mid_py_setup.Rd
d4c23b45ca9cbffa53fc72c99ea0d56e *man/overimpute.Rd
fd482c198c4096b5eb1c5a0c6941c3e1 *man/python_configured.Rd
67d01f8dd1cf19b84a79632f047922f4 *man/python_init.Rd
d575e14c0779057cbd2ebf57d535175a *man/reset_rMIDAS_env.Rd
02377b2e452e4f904da3e723ec4fbbac *man/set_python_env.Rd
2aaaff54cab764411588113f92dbc22a *man/skip_if_no_numpy.Rd
5cd0176f8448ae970c45b1dce8caee50 *man/train.Rd
499c92fc7cdd4e54e555f49b27dd88c9 *man/undo_minmax.Rd
316d76f801fd61c6d2121a1687c0c4cd *tests/testthat.R
d7ce0a0c02e69876725d5e39cc609feb *tests/testthat/testAnalysis.R
aaee589ee89b5f9b3a27daa0972584a8 *tests/testthat/testPreProc.R
0c307d22142c8b940bb2eabf7a171f66 *vignettes/custom_python_versions.Rmd
8fb23fc2e93eee5bb937a21099ca4563 *vignettes/imputation_demo.Rmd
c76d8adb11b29e50e59045f93bc2e908 *vignettes/custom_python_versions.Rmd
d798e49212ef190161166bd9e79769a8 *vignettes/custom_python_versions.md
04d83b9a9a4b7ff88610d4ea2a006b13 *vignettes/imputation_demo.Rmd
42078208940fb77bd684290299d9c473 *vignettes/imputation_demo.md
ae13282efbb233718090fd8323aad0e0 *vignettes/use-server.Rmd
250f2bb51afbce61591cd4ec4f68ab66 *vignettes/use-server.md
2 changes: 2 additions & 0 deletions NAMESPACE
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
14 changes: 11 additions & 3 deletions NEWS.md
@@ -1,11 +1,19 @@
# rMIDAS 0.4
# rMIDAS 0.5

## v0.5.0
* 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 functions
* 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.2
* Added headless functionality to `matplotlib` calls in Python
* Added headless functionality to matplotlib calls in Python
* Updated conda setup file
* Minor updates to underlying Python code to address deprecation issues


## v0.4.1
* Disabled Tensorflow deprecation warnings as default (as Python rather than R warning)
* Updated accompanying YAML for easier Conda setup
Expand Down
40 changes: 40 additions & 0 deletions R/delete_env.R
@@ -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
@@ -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.")
}
121 changes: 118 additions & 3 deletions R/zzz.R
@@ -1,17 +1,132 @@
.onLoad <- function(libname, pkgname) {
custom_readline <- function(prompt, default = "skip") {
if (interactive()) {
return(readline(prompt))
} else {
return(default)
}
}

custom_writelines <- function(input, con) {
writeLines(input, con = con)
}

custom_packageStartupMessage <- function(msg) {
messages <- list(
msg1 = "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.",
msg2 = "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.",
msg3 = "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.",
msg4 = "rMIDAS is being set up automatically.",
msg5 = "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.",
msg6 = "rMIDAS has been automatically set up.",
msg7 = "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."
)
packageStartupMessage(messages[msg])
}

.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"
custom_packageStartupMessage("msg1")
custom_packageStartupMessage("msg2")
} else {
user_input <- custom_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", default = "n")
custom_writelines(user_input, con = config_file)
if(tolower(user_input) != "y") {custom_packageStartupMessage("msg3")}
if(tolower(user_input) == "y") {custom_packageStartupMessage("msg4")}
}
} else {
user_input <- readLines(con = config_file)[1]
if(tolower(user_input) != "y") {
custom_packageStartupMessage("msg5")
custom_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")
custom_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)
custom_packageStartupMessage("msg6")
}
custom_packageStartupMessage("msg7")
}
}

.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
}

0 comments on commit 9acf8fa

Please sign in to comment.