Skip to contents

[Stable] Reads code from specified files or an R6 object.

  • if reading from R6: get the R code stored inside the object.

  • if reading from files: Includes code from source if reading from files. Method reads code without

library() or require() calls. Function created for teal app, but can be used with any file. Get code from certain files and for specific datasets

Reads code from specified files and specific code chunks.

Code chunks are described with:

  • to open chunk #code> or #code ADSL> or #code ADSL ADTTE>

  • to close chunk #<code or #<ADSL code or #<ADSL ADTTE code

Usage

get_code(x, ...)

# S3 method for TealDatasetConnector
get_code(x, deparse = TRUE, ...)

# S3 method for TealDataset
get_code(x, deparse = TRUE, ...)

# S3 method for TealDataAbstract
get_code(x, dataname = character(0), deparse = TRUE, ...)

# S3 method for default
get_code(
  x,
  exclude_comments = TRUE,
  read_sources = TRUE,
  deparse = FALSE,
  files_path = NULL,
  dataname = NULL,
  ...
)

Arguments

x

(TealDatasetConnector or TealDataset). If of class character will be treated as file to read.

...

not used, only for support of S3

deparse

(logical) whether return deparsed form of a call

dataname

(character) Name of dataset to return code for.

exclude_comments

(logical) whether exclude commented-out lines of code. Lines to be excluded should be ended with # nocode. For multiple line exclusions one should enclose ignored block of code with # nocode> and # <nocode

read_sources

(logical) whether to replace source("path") with code lines from sourced file. If read_sources = TRUE changing working directory inside preprocessing is not allowed.

files_path

(character) (optional) vector of files path to be read for preprocessing. Code from multiple files is joined together.

Value

(character) code of import and preparation of data for teal application.

Examples

x1 <- dataset(
  x = data.frame(x = c(1, 2), y = c("a", "b"), stringsAsFactors = FALSE),
  keys = "y",
  dataname = "XY",
  code = "XY <- data.frame(x = c(1, 2), y = c('aa', 'bb'), stringsAsFactors = FALSE)",
  label = character(0)
)

x2 <- dataset(
  x = data.frame(x = c(1, 2), y = c("a", "b"), stringsAsFactors = FALSE),
  keys = "y",
  dataname = "XYZ",
  code = "XYZ <- data.frame(x = c(1, 2), y = c('aa', 'bb'), stringsAsFactors = FALSE)",
  label = character(0)
)

rd <- teal_data(x1, x2)

get_code(rd)
#> [1] "XY <- data.frame(x = c(1, 2), y = c(\"aa\", \"bb\"), stringsAsFactors = FALSE)\nXYZ <- data.frame(x = c(1, 2), y = c(\"aa\", \"bb\"), stringsAsFactors = FALSE)"
get_code(rd, "XY")
#> [1] "XY <- data.frame(x = c(1, 2), y = c(\"aa\", \"bb\"), stringsAsFactors = FALSE)"
get_code(rd, "XYZ")
#> [1] "XYZ <- data.frame(x = c(1, 2), y = c(\"aa\", \"bb\"), stringsAsFactors = FALSE)"