loading...

These functions just change the class of the object by reference (data.trame and data.table objects are, internally, identical except for their class). These functions are intended only for programmers! There is no check that the object is correct before the change.

let_data.table_to_data.trame(x)

let_data.trame_to_data.table(x)

Arguments

x

A valid data.trame or data.table object

Value

A data.table or data.trame object.

Examples

dtrm <- data.trame(a = 1:3, b = letters[1:3], c = factor(LETTERS[1:3]))
class(dtrm)
#> [1] "data.trame" "data.frame"
let_data.trame_to_data.table(dtrm)
class(dtrm)
#> [1] "data.table" "data.frame"
let_data.table_to_data.trame(dtrm)
class(dtrm)
#> [1] "data.trame" "data.frame"

# Whenever you need to use a data.table method on a data.trame in a function,
# you can do something like this:
test_fun <- function(x, i, expr) {
  force(i) # Make sure i is evaluated before changing the class of x
  # value will be evaluated with x being a data.table here!
  let_data.trame_to_data.table(x)
  on.exit(let_data.table_to_data.trame(x))
  print(class(x)) # Internally, it is now a data.table
  expr
}
test_fun(dtrm, 1:2, class(dtrm))
#> [1] "data.table" "data.frame"
#> [1] "data.trame" "data.frame"
class(dtrm) # Back to data.trame
#> [1] "data.trame" "data.frame"