Skip to content

Commit

Permalink
Merge pull request #3 from dynverse/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
zouter committed Apr 9, 2019
2 parents 54f7711 + 45dba4b commit f53e50f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 92 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dyncli
Type: Package
Title: CLI helper package for creating TI containers
Version: 0.0.2
Version: 0.0.2.9000
Authors@R: c(
person(
"Robrecht",
Expand Down Expand Up @@ -51,9 +51,9 @@ Imports:
tidyr,
yaml
Remotes:
dynverse/dynparam@master,
dynverse/dynutils@master,
dynverse/dynwrap@master
dynverse/dynparam@devel,
dynverse/dynutils@devel,
dynverse/dynwrap@devel
VignetteBuilder: knitr
Suggests:
knitr,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(create_ti_method_definition)
export(main)
export(write_output)
import(assertthat)
Expand Down
19 changes: 13 additions & 6 deletions R/main.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
#' @param args The arguments to be read by dyncli
#' @param definition_location The location of the definition file of the method
#'
#'
#'
#' @importFrom optparse OptionParser add_option make_option parse_args
#' @importFrom dynwrap create_ti_method_definition
#' @importFrom yaml read_yaml
#' @importFrom dynwrap create_ti_method_definition
#'
#' @export
main <- function(
Expand Down Expand Up @@ -70,14 +72,23 @@ main <- function(
# add final parameters
add_option("--verbosity", type = "integer", default = 1, help = "The verbosity level: 0 => none, 1 => critical (default), 2 => info, 3 => debug.") %>%
add_option("--seed", type = "integer", help = "A seed to be set to ensure reproducibility.") %>%
add_option("--debug", type = "logical", default = FALSE)
add_option("--debug", action = "store_true")


debug("Parsing arguments\n")

parsed_args <- parse_args(parser, args = args)
debug("Arguments:\n", paste(deparse(parsed_args), collapse = "\n"), "\n")

# if debug, return command to debug
if (isTRUE(parsed_args$debug)) {
args <- args[args != "--debug"]
args_debug <- paste0(deparse(args, width.cutoff = 500), collapse = "\n")
command <- paste0("task <- dyncli::main(", args_debug, ")", collapse = "")
cat("Use this command inside R to load the data: \n", crayon::bold(command), "\n")
quit(save = "no")
}

##########################################
## PARSE TASK ##
##########################################
Expand Down Expand Up @@ -200,10 +211,6 @@ main <- function(

info("Finished processing data\n")

if (isTRUE(task$debug)) {
browser()
}

task
}

61 changes: 0 additions & 61 deletions R/method_create_ti_method_definition.R
Original file line number Diff line number Diff line change
@@ -1,61 +0,0 @@
#' Create a TI method from a local method definition file
#'
#' The local method definition file describes a method that is runnable on the local system.
#'
#' @param script Location of the script that will be executed. Has to contain a #!
#' @inheritParams dynwrap:::.method_process_definition
#'
#' @keywords create_ti_method
#'
#' @importFrom yaml read_yaml
#'
#' @export
create_ti_method_definition <- function(
definition,
script,
return_function = TRUE
) {
definition_path <- definition
definition <- dynwrap:::.method_load_definition(definition)

definition$run <- list(
backend = "script",
script = script,
definition = definition_path
)

dynwrap:::.method_process_definition(definition = definition, return_function = return_function)
}


.method_execution_execute_script <- function(method, preproc_meta) {
# copy over script and rds
file.copy(normalizePath(method$run$script), preproc_meta$dir_dynwrap)
script_location <- basename(method$run$script)
file.copy(normalizePath(method$run$definition), paste0(preproc_meta$dir_dynwrap, "/definition.yml"))

# print information if desired
if (preproc_meta$verbose) {
cat("Input saved to ", preproc_meta$dir_dynwrap, "\n", sep = "")
}

# run script
command <- paste0("./", script_location)
args <- c("--dataset", "input.h5", "--output", "output.h5")

if (preproc_meta$debug) {
stop(paste0(c(command, args), collapse = " "))
}

process <- processx::run(
command = command,
args = args,
wd = preproc_meta$dir_dynwrap,
echo = preproc_meta$verbose,
echo_cmd = as.logical(preproc_meta$verbose) || preproc_meta$debug,
spinner = TRUE
)

# return output
dynutils::read_h5(file.path(preproc_meta$dir_dynwrap, "output.h5"))
}
19 changes: 0 additions & 19 deletions man/create_ti_method_definition.Rd

This file was deleted.

8 changes: 8 additions & 0 deletions tests/testthat/test-create_ti_method_definition.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ dyncli::write_output(trajectory, dataset$output)

readr::write_file(run_r_string, "run.R")

system("chmod +x run.R")

method <- create_ti_method_definition("definition.yml", "run.R")

dataset <- dynwrap::example_dataset

trajectory <- dynwrap::infer_trajectory(dataset, method())

expect_true(dynwrap::is_wrapper_with_trajectory(trajectory))

file.remove("definition.yml")
file.remove("run.R")
})
3 changes: 2 additions & 1 deletion vignettes/create_ti_method_script.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ vignette: >

```{r setup}
library(dynwrap)
library(dyncli)
```

An alternative to wrapping a script inside R, is to wrap it using an external script. Because this does not provide any dependency management, this is not really useful for method end-users, but rather as a way to easily develop a TI method and to ultimately step up towards [containerised wrapping](../create_ti_method_container).
Expand Down Expand Up @@ -142,7 +143,7 @@ method <- create_ti_method_definition(
"run.R"
)
dataset <- dynwrap::example_dataset
trajectory <- infer_trajectory(dataset, method(), verbose = TRUE)
trajectory <- infer_trajectory(dataset, method(), verbose = TRUE, debug = TRUE)
```


Expand Down

0 comments on commit f53e50f

Please sign in to comment.