Skip to contents

[Experimental] Please note that the script has to end with a call creating desired object. The error will be raised otherwise.

Usage

dataset_file(path, code = get_code(path))

Arguments

path

(character) string giving the pathname of the file to read from.

code

(character) reproducible code to re-create object

Value

TealDataset object

Examples

# simple example
file_example <- tempfile(fileext = ".R")
writeLines(
  text = c(
    "library(teal.data)
     dataset(dataname = \"iris\",
             x = iris,
             code = \"iris\")"
  ),
  con = file_example
)
x <- dataset_file(file_example, code = character(0))
get_code(x)
#> [1] "iris"

# custom code
file_example <- tempfile(fileext = ".R")
writeLines(
  text = c(
    "library(teal.data)

     # code>
     x <- iris
     x$a1 <- 1
     x$a2 <- 2

     # <code
     dataset(dataname = \"iris_mod\", x = x)"
  ),
  con = file_example
)
x <- dataset_file(file_example)
get_code(x)
#> [1] "x <- iris\nx$a1 <- 1\nx$a2 <- 2"