Skip to content

Commit

Permalink
update examples to satisfy dontrun and add SysReq to desc
Browse files Browse the repository at this point in the history
  • Loading branch information
tsrobinson committed Feb 9, 2022
1 parent 5f3db7d commit fd553cf
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 73 deletions.
134 changes: 67 additions & 67 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,70 +1,3 @@
Sys.time()
py(model)
reticulate::py_call(model)
reticulate::py_call("model")
py_run_string("print(model)")
py_run_string("model")
py_run_string('print(model)')
?r_to_py
set.seed(89)
## Read data for analysis
cat_vars <- c("CC18_401","CC18_413d","educ","race","marstat","votereg","OScode","CompRating",
"region","pid7","immstat","employ","sexuality","trans","industryclass","pew_churatd")
bin_vars <- c("CC18_415a","CC18_417_a","gender")
cont_vars <- c("citylength_1","numchildren","birthyr")
data_0_test <- fread("data/cces_jss_format.csv", select = c(cat_vars, bin_vars, cont_vars))
r_to_py(data_0_test)
py_run_string("print(data_0_test")
py_run_string("print(data_0_test)")
py_load_object(data_0_test)
py$data_0_test <- data_0_test
py_run_string("print(data_0_test")
py_run_string("print(data_0_test)")
cces <- read_csv("../linux/JSS/replication_materials/data/cces_jss_format.csv")
library(tidyverse)
cces <- read_csv("../linux/JSS/replication_materials/data/cces_jss_format.csv")
print(object.size(cces), "Mb")
print(object.size(cces),units = "Mb")
library(devtools)
check()
check_rhub()
build()
# Imputation workflow
library("rMIDAS")
install.packages("rMIDAS")
library(rMIDAS)
version(rMIDAS)
data(quakes)
force(quakes)
data(airquality)
x_conv <- convert(add_missingness(quakes, prop=0.1),
minmax_scale = TRUE)
x_train <- train(x_conv,
training_epochs = 20,
layer_structure = c(128,128),
input_drop = 0.75,
seed = 89)
force(airquality)
x_complete <- complete(x_train, m = 1)
?complete
complete2 <- function(mid_obj,
m=10L,
unscale = TRUE,
bin_label = TRUE,
cat_coalesce = TRUE,
fast = FALSE,
file = NULL,
file_root = NULL) {
if (!inherits(mid_obj,"midas_base.Midas")) {
stop("Trained midas object not supplied to 'mid_obj' argument")
}
if (is.null(options("python_initialised")$python_initialised)) {
python_init()
}
if (!("preproc" %in% names(mid_obj))) {
unscale = FALSE
bin_label = FALSE
cat_coalesce = FALSE
}
draws <- mid_obj$generate_samples(m = as.integer(m))$output_list
if ((unscale || bin_label || cat_coalesce)) {
Expand Down Expand Up @@ -510,3 +443,70 @@ library(devtools)
install_github("MIDASverse/rMIDAS")
library(rMIDAS)
vignette(package = "rMIDAS")
library(devtools)
check()
release()
library(Amelia)
data(quakes)
quakes_missing <- add_missingess(quakes)
library(rMIDAS)
quakes_missing <- add_missingess(quakes)
quakes_missing <- add_missingess(quakes)
quakes_missing <- add_missingness(quakes)
quakes_missing <- add_missingness(quakes, 0.1)
amelia(quakes_missing, m = 1)
quakes_complete <- amelia(quakes_missing, m = 1)
quakes_complete$imputations[[1]]
quakes$cat <- sample(c("a","b","c"), length(quakes), replace = TRUE)
quakes
quakes_missing <- add_missingness(quakes, 0.1)
quakes_complete$imputations[[1]]
quakes_complete <- amelia(quakes_missing, m = 1)
quakes_complete <- amelia(quakes_missing, m = 1, noms = c("cat"))
quakes_complete$imputations$imp1
library(Amelia)
data(quakes)
quakes
quakes$cat <- sample(c("a","b","c"), nrow(quakes), replace = TRUE)
quakes
quakes <- add_missingness(quakes, 0.3)
quakes
quakes$ord <- sample(c("1","2","3","4","5"), nrow(quakes), replace = TRUE)
quakes
data(quakes)
quakes$cat <- sample(c("a","b","c"), nrow(quakes), replace = TRUE)
quakes$ord <- sample(c("1","2","3","4","5"), nrow(quakes), replace = TRUE)
quakes
quakes <- add_missingness(quakes, 0.3)
quakes
quakes_complete <- amelia(quakes, m = 1,
noms = c("cat"),
ords = c("ord"))
quakes_complete <- amelia(quakes, m = 1,
noms = c("cat"))
data(quakes)
quakes$cat <- sample(c("a","b","c"), nrow(quakes), replace = TRUE)
quakes$ord <- as.factor(sample(c("1","2","3","4","5"), nrow(quakes), replace = TRUE))
quakes
quakes <- add_missingness(quakes, 0.3)
quakes
quakes_complete <- amelia(quakes, m = 1,
noms = c("cat"),
ords = c("ord"))
levels(quakes$ord)
quakes$ord <- factor(sample(c("1","2","3","4","5"), nrow(quakes), replace = TRUE),
levels = c("1","2","3","4","5"))
levels(quakes$ord)
data(quakes)
quakes$cat <- sample(c("a","b","c"), nrow(quakes), replace = TRUE)
quakes$ord <- factor(sample(c("1","2","3","4","5"), nrow(quakes), replace = TRUE),
levels = c("1","2","3","4","5"))
quakes
quakes <- add_missingness(quakes, 0.3)
quakes
quakes
quakes_complete <- amelia(quakes, m = 1,
noms = c("cat"),
ords = c("ord"))
quakes_data <- quakes_complete$imputations$imp1
quakes_data
4 changes: 2 additions & 2 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.4.0
Date: 2022-02-02 18:01:53 UTC
SHA: 6c541724f900f731cccf89e5d31a2f01c63582eb
Date: 2022-02-03 10:00:51 UTC
SHA: 5f3db7d61491ce824eda52b4080544898444d8db
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Suggests:
testthat,
knitr,
rmarkdown
SystemRequirements: Python (>= 2.7.0)
VignetteBuilder: knitr
License: Apache License (>= 2.0)
URL: https://github.com/MIDASverse/rMIDAS
Expand Down
20 changes: 20 additions & 0 deletions R/load_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,23 @@ skip_if_no_numpy <- function() {
if (!have_numpy)
testthat::skip("numpy not available for testing")
}

#' Check whether Python is capable of executing example code
#'
#' Checks if each Python dependency is available.
#' This function is called within some examples to ensure code executes properly.
#' @keywords setup
#' @return `NULL`
python_configured <- function() {

py_dep <- c("matplotlib","numpy","pandas","tensorflow","sklearn","os","random", "tensorflow_addons")
dep_avail <- sapply(py_dep, function (x) reticulate::py_module_available(x))

if (sum(dep_avail) == length(py_dep)) {
return(TRUE)
} else {
return(FALSE)
}
}


4 changes: 2 additions & 2 deletions inst/examples/basic_workflow.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generate raw data, with numeric, binary, and categorical variables
\dontrun{
# Run where Python available
if (reticulate::py_module_available("numpy")) {
# Run where Python available and configured correctly
if (python_configured()) {
set.seed(89)
n_obs <- 10000
raw_data <- data.table(a = sample(c("red","yellow","blue",NA),n_obs, replace = TRUE),
Expand Down
4 changes: 2 additions & 2 deletions inst/examples/overimputation.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
\dontrun{
# Run where Python available
if (reticulate::py_module_available("numpy")) {
# Run where Python available and configured correctly
if (python_configured()) {

raw_data <- data.table(a = sample(c("red","yellow","blue",NA),1000, replace = TRUE),
b = 1:1000,
Expand Down

0 comments on commit fd553cf

Please sign in to comment.