S4 class container for storing R-based code for a workflow step. LineWise class instances are constructed by the LineWise function, based on the R-based code, step name, and dependency tree. When the container is built from the R Markdown, using importWF function, two other slots are populated: codeChunkStart and rmdPath. codeChunkStart will store the first line of each R chunk, and rmdPath will store the R Markdown file path.

## Constructor

LineWise(code, step_name = "default", codeChunkStart = integer(), 
            rmdPath = character(), dependency="", 
            run_step = "mandatory",
            run_session = "management", 
            run_remote_resources = NULL)

Arguments

code

R code separated either by a semi-colon (\;), or by a newline, and enclosed by braces ({ }).

step_name

character. Step name needs to be unique and is required when appending this step to the workflow.

codeChunkStart

integer. R Markdown code chunk line start. This element will be populated when the object is built by importWF.

rmdPath

character. Path of R Markdown file used by importWF.

dependency

character. Dependency tree, required when appending this step to the workflow. Character name of a previous step in the workflow. Default is empty string "".

run_step

character. If the step has "mandatory" or "optional" flag for the execution.

run_session

character. If the step has "management" or "compute" flag for the execution.

run_remote_resources

List for reserving for each cluster job sufficient computing resources including memory (Megabyte), number of nodes, CPU cores, walltime (minutes), etc. It is necessary two aditional files: conffile and template. conffile is the path to conf file (default location ./.batchtools.conf.R). This file contains in its simplest form just one command, such as this line for the Slurm scheduler: cluster.functions <- makeClusterFunctionsSlurm(template="batchtools.slurm.tmpl"). For more detailed information visit this page: https://mllg.github.io/batchtools/index.html template The template files for a specific queueing/scheduling systems can be downloaded from here: https://github.com/mllg/batchtools/tree/master/inst/templates. Slurm, PBS/Torque, and Sun Grid Engine (SGE) templates are provided

Objects from the Class

Objects can be created by calls of the form new("LineWise", ...).

Slots

codeLine:

Object of class "expression" storing R-based code.

codeChunkStart:

Object of class "interger" storing start line from the rmdPath file, when the "LineWise" is built from R Markdown.

stepName:

Object of class "character" storing step name.

dependency:

Object of class "list" storing dependency tree.

status:

Object of class "list" storing status steps.

files:

Object of class "list" storing file for R Markdown file and the file containing stdout and stderr after running the R-based code.

runInfo:

Object of class "list" storing all the runInfo information of the workflow

Functions and Methods

See 'Usage' for details on invocation.

Constructor:

LineWise:

Returns a LineWise object.

Accessors:

% Accessors
codeLine

Printing method for the CodeLine slot.

codeChunkStart

Extract start line of the R Markdown R chunk.

rmdPath

Extract Rmarkdown file path.

stepName

Extract the step name.

dependency

Extract the dependency tree.

status

Extract status of the step.

files

Extract log file path storing stdout and stderr after running step.

% Replacement
appendCodeLine<-

Replacement method for append a R code line.

replaceCodeLine<-

Replacement method for replace a R code line.

Methods:

% General
[

Return a new LineWise object made of the selected R code lines.

[[

Extract the slot information from LineWine object.

[[<-

Replacement method for LineWine slots.

$

Extract slots elements by name.

length

Extract number of R-based code lines.

names

Extract slot names.

show

Summary view of LineWise elements.

% Coerce
coerce

signature(from = "LineWise", to = "list")as(LineWise, "list")

coerce

signature(from = "list", to = "LineWise")as(list, "LineWise")

linewise

Coerce back to list as(LineWise, "list")

Author

Daniela Cassol

See also

Examples

showClass("LineWise")
#> Class "LineWise" [package "systemPipeR"]
#> 
#> Slots:
#>                                                                   
#> Name:        codeLine codeChunkStart       stepName     dependency
#> Class:     expression        integer      character           list
#>                                                    
#> Name:          status          files        runInfo
#> Class:           list           list           list
lw <- LineWise(code = {
              log_out <- log(10)
              },
              step_name = "R_log")

codeLine(lw)
#> log_out <- log(10)

## ImportWF option
file_path <- system.file("extdata/spr_simple_lw.Rmd", package="systemPipeR")
sal <- SPRproject(overwrite = TRUE)
#> Creating directory:  /home/runner/work/systemPipeR/systemPipeR/docs/reference/data 
#> Creating directory:  /home/runner/work/systemPipeR/systemPipeR/docs/reference/param 
#> Creating directory:  /home/runner/work/systemPipeR/systemPipeR/docs/reference/results 
#> Creating directory '/home/runner/work/systemPipeR/systemPipeR/docs/reference/.SPRproject'
#> Creating file '/home/runner/work/systemPipeR/systemPipeR/docs/reference/.SPRproject/SYSargsList.yml'
# file_path <- "../inst/extdata/spr_simple_lw.Rmd"
sal <- importWF(sal, file_path)
#> Reading Rmd file
#> 
#> 
#>  ---- Actions ----
#> Checking chunk eval values
#> Checking chunk SPR option
#> Ignore non-SPR chunks: 17
#> Parse chunk code
#> Checking preprocess code for each step
#> No preprocessing code for SPR steps found
#> Now importing step 'firstStep' 
#> Now importing step 'secondStep' 
#> Now back up current Rmd file as template for `renderReport`
#> Template for renderReport is stored at 
#>  /home/runner/work/systemPipeR/systemPipeR/docs/reference/.SPRproject/workflow_template.Rmd 
#>  Edit this file manually is not recommended 
#> Now check if required tools are installed 
#> There is no commandline (SYSargs) step in this workflow, skip.
#> Import  done
#> 
sal <- runWF(sal)
#> Running Step:  firstStep 
#> Running Session: Management 
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
#> Step Status:  Success 
#> Running Step:  secondStep 
#> Running Session: Management 
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |======================================================================| 100%
#> Step Status:  Success 
#> Done with workflow running, now consider rendering logs & reports
#> To render logs, run:    sal <- renderLogs(sal)
#> From command-line:      Rscript -e "sal = systemPipeR::SPRproject(resume = TRUE); sal = systemPipeR::renderLogs(sal)"
#> To render reports, run: sal <- renderReport(sal)
#> From command-line:      Rscript -e "sal= s ystemPipeR::SPRproject(resume = TRUE); sal = systemPipeR::renderReport(sal)"
#> This message is displayed once per R session
#> 
lw2 <- sal$stepsWF[[2]]
lw2
#> Instance of 'LineWise'
#>     Code Chunk length: 3
names(lw2)
#> [1] "codeLine"       "codeChunkStart" "stepName"       "dependency"    
#> [5] "status"         "files"          "runInfo"       
length(lw2)
#> [1] 3

## Accessors
codeLine(lw2)
#> setosa <- read.delim("results/setosa.csv", sep = ",")
#> versicolor <- read.delim("results/versicolor.csv", sep = ",")
#> virginica <- read.delim("results/virginica.csv", sep = ",")
codeChunkStart(lw2)
#> integer(0)
rmdPath(lw2)
#> NULL
stepName(lw2)
#> [1] "secondStep"
dependency(lw2)
#> $secondStep
#> [1] "firstStep"
#> 
status(lw2)
#> $status.summary
#> [1] "Success"
#> 
#> $status.completed
#>         Step  Status
#> 1 secondStep Success
#> 
#> $status.time
#>         Step          time_start            time_end
#> 1 secondStep 2023-05-11 01:52:42 2023-05-11 01:52:42
#> 
#> $total.time
#> $total.time$time_start
#> [1] "2023-05-11 01:52:42 UTC"
#> 
#> $total.time$time_end
#> [1] "2023-05-11 01:52:42 UTC"
#> 
#> 
files(lw2)
#> $log
#> [1] ".SPRproject/Rsteps/_logRstep_secondStep_May112023_015242"
#> 

## Replacement
appendCodeLine(lw2, after = 0) <- "log <- log(10)"
codeLine(lw2)
#> log <- log(10)
#> setosa <- read.delim("results/setosa.csv", sep = ",")
#> versicolor <- read.delim("results/versicolor.csv", sep = ",")
#> virginica <- read.delim("results/virginica.csv", sep = ",")
replaceCodeLine(lw2, 1) <- "plot(iris)"
codeLine(lw2)
#> plot(iris)
#> setosa <- read.delim("results/setosa.csv", sep = ",")
#> versicolor <- read.delim("results/versicolor.csv", sep = ",")
#> virginica <- read.delim("results/virginica.csv", sep = ",")

## Coerce
lw2 <- linewise(lw2) ## OR lw2 <- as(lw2, "list") 
lw2 <- as(lw2, "LineWise")