Skip to content

Commit

Permalink
Merge 42ebce8 into c32c7c3
Browse files Browse the repository at this point in the history
  • Loading branch information
AEBilgrau committed Jun 15, 2019
2 parents c32c7c3 + 42ebce8 commit 2a77ee8
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 105 deletions.
8 changes: 1 addition & 7 deletions .Rbuildignore
Expand Up @@ -15,12 +15,6 @@ Makefile
inst/shiny/rsconnect

# Generated files in inst/shiny/www/..
inst/shiny/*
inst/shiny/www/report_full.Rmd
inst/shiny/www/report_full.html
inst/shiny/www/report_full_purl.R
inst/shiny/www/report_meta.Rmd
inst/shiny/www/report_meta.html
inst/shiny/www/report_meta_purl.R
inst/shiny/www/report_expanded.*
data/freshVsFrozen.csv
data/u133VsExon.csv
6 changes: 6 additions & 0 deletions .travis.yml
Expand Up @@ -16,7 +16,13 @@ r_github_packages:
after_success:
- Rscript -e 'covr::coveralls()'

after_failure:
- Rscript -e 'sessionInfo()'
- Rscript -e 'installed.packages()'

notifications:
email:
on_success: change
on_failure: change


1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -24,6 +24,7 @@ Suggests:
rmarkdown,
shiny,
shinydashboard,
shinyBS,
rhandsontable,
DT
VignetteBuilder: knitr
Expand Down
2 changes: 1 addition & 1 deletion GMCM.Rproj
Expand Up @@ -18,7 +18,7 @@ StripTrailingWhitespace: Yes

BuildType: Package
PackageInstallArgs: --resave-data
PackageBuildArgs: --resave-data --compact-vignettes=both
PackageBuildArgs: --resave-data --compact-vignettes=both --with-keep.source
PackageBuildBinaryArgs: --resave-data
PackageCheckArgs: --as-cran
PackageRoxygenize: rd,namespace
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -39,4 +39,5 @@ importFrom(stats,rchisq)
importFrom(stats,rnorm)
importFrom(stats,runif)
importFrom(utils,flush.console)
importFrom(utils,write.csv2)
useDynLib(GMCM)
7 changes: 7 additions & 0 deletions R/cput.R
@@ -0,0 +1,7 @@
# dput object to character string
# cput is used inside the reports
cput <- function(x) {
f <- tempfile()
dput(x, file = f)
return(readLines(f))
}
51 changes: 51 additions & 0 deletions R/run_full_report.R
@@ -0,0 +1,51 @@
#' @importFrom utils write.csv2
run_full_report <- function(...) {

# Simulate some data and put it into a CSV file
sim_data <- SimulateGMCMData(n = 1000, par = c(pie1 = 0.3, mu = 2,
sigma = 1.1, rho = 0.2))$z
colnames(sim_data) <- c("u133", "exon")
data_file <- tempfile()
utils::write.csv2(sim_data, file = data_file)


# SPECIAL GMCM ----
report_path_meta <- system.file("shiny", "www", "report_meta.Rmd",
package = "GMCM", lib.loc = .libPaths()[1],
mustWork = TRUE)

# Parameters to expand
params <- list(data_file = data_file,
header = TRUE,
sep = ";",
quote = '\"',
model_cols = c("u133", "exon"),
meta_large_vals = FALSE,
init_par = c(pie1 = 0.5, mu = 1, sigma = 1, rho = 0.5),
meta_method = "NM",
meta_max_ite = 50,
meta_positive_rho = TRUE,
meta_IDR_thres_type = "IDR",
meta_IDR_thres = 0.01)

expand_args <- c(list(file = report_path_meta), params)
report_expanded <- do.call(knitr::knit_expand, expand_args)

# Write to file
report_expanded_path <- tempfile()
cat(report_expanded, file = report_expanded_path)

# We can also purl
res1 <- knitr::purl(report_expanded_path,
output = gsub(".Rmd$", ".R", report_expanded_path),
documentation = 0)

# Render the expanded document
res2 <- rmarkdown::render(
input = report_expanded_path,
output_options = list(self_contained = TRUE),
envir = new.env(parent = globalenv())
)

return(invisible(list(report_expanded_path, res1, res2)))
}
49 changes: 49 additions & 0 deletions R/run_meta_report.R
@@ -0,0 +1,49 @@
#' @importFrom utils write.csv2
run_meta_report <- function(...) {

# Simulate some data and put it into a CSV file
sim_data <- SimulateGMCMData(n = 1000, par = c(pie1 = 0.3, mu = 2,
sigma = 1.1, rho = 0.2))$z
colnames(sim_data) <- c("u133", "exon")
data_file <- tempfile()
utils::write.csv2(sim_data, file = data_file)


# GENERAL GMCM ----
report_path_full <- system.file("shiny", "www", "report_full.Rmd",
package = "GMCM", lib.loc = .libPaths()[1],
mustWork = TRUE)

# Parameters to expand
params <- list(data_file = data_file,
header = TRUE,
sep = ";",
quote = '\"',
model_cols = c("u133", "exon"),
theta = GMCM::rtheta(m = 2, d = 2),
fit_method = "NM",
max_ite = 50,
full_class_type = "thres_prob",
full_thres_prob = 0.9)

expand_args <- c(list(file = report_path_full), params)
report_expanded <- do.call(knitr::knit_expand, expand_args)

# Write to temp file
report_expanded_path <- tempfile()
cat(report_expanded, file = report_expanded_path)

# We can purl
res3 <- knitr::purl(report_expanded_path,
output = paste0(report_expanded_path, ".R"),
documentation = 0)

# Render the expanded document
res4 <- rmarkdown::render(
input = report_expanded_path,
output_options = list(self_contained = TRUE),
envir = new.env(parent = globalenv())
)

return(invisible(list(report_expanded_path, res3, res4)))
}
91 changes: 0 additions & 91 deletions inst/shiny/run-reports.R

This file was deleted.

8 changes: 2 additions & 6 deletions tests/testthat/test-shiny-reports.R
Expand Up @@ -4,12 +4,8 @@ test_that("shiny reports can be expanded and rendered", {
skip_on_cran()

# Expect no errors (i.e. fail to provide errors)
expect_error(
capture_messages(capture_output( # Make render shut up
source(system.file("shiny/run-reports.R", package = "GMCM"))
)),
NA
)
expect_error(GMCM:::run_meta_report(), NA)
expect_error(GMCM:::run_full_report(), NA)
})


Expand Down

0 comments on commit 2a77ee8

Please sign in to comment.