R/dtx.R
dtx.Rd
Create a data frame (data.trame, base's data.frame, data.table or tibble's tbl_df)
dtx(..., .name_repair = c("check_unique", "unique", "universal", "minimal"))
dtrm(..., .name_repair = c("check_unique", "unique", "universal", "minimal"))
dtbl(..., .name_repair = c("check_unique", "unique", "universal", "minimal"))
dtf(..., .name_repair = c("check_unique", "unique", "universal", "minimal"))
dtt(..., .name_repair = c("check_unique", "unique", "universal", "minimal"))
A data frame as a data.trame object for dtrm()
, a tbl_df object
for dtbl()
, a data.frame for dtf()
or a data.table for dtt()
.
data.trame, data.table and tibble's tbl_df do no use row names.
However, you can add a column named .rownames
(by default), or the name that
is in getOption("SciViews.dtx.rownames")
and it will be automatically set as
row names when the object is converted into a data.frame with as_dtf()
. For
dtf()
, just create a column of this name and it is directly used as row
names for the resulting data.frame object.
dtrm1 <- dtrm(
x = 1:5,
y = rnorm(5),
f = letters[1:5],
l = sample(c(TRUE, FALSE), 5, replace = TRUE)
)
class(dtrm1)
#> [1] "data.trame" "data.frame"
dtbl1 <- dtbl(
x = 1:5,
y = rnorm(5),
f = letters[1:5],
l = sample(c(TRUE, FALSE), 5, replace = TRUE)
)
class(dtbl1)
#> [1] "tbl_df" "tbl" "data.frame"
dtf1 <- dtf(
x = 1:5,
y = rnorm(5),
f = letters[1:5],
l = sample(c(TRUE, FALSE), 5, replace = TRUE)
)
class(dtf1)
#> [1] "data.frame"
dtt1 <- dtt(
x = 1:5,
y = rnorm(5),
f = letters[1:5],
l = sample(c(TRUE, FALSE), 5, replace = TRUE))
class(dtt1)
#> [1] "data.table" "data.frame"
# Using dtx(), one construct the preferred data frame object
# (a data.trame by default, can be changed with options(SciViews.as_dtx = ...))
dtx1 <- dtx(
x = 1:5,
y = rnorm(5),
f = letters[1:5],
l = sample(c(TRUE, FALSE), 5, replace = TRUE))
class(dtx1) # data.trame by default
#> [1] "data.trame" "data.frame"
# Use dtx_rows() to easily create a data frame:
dtx2 <- dtx_rows(
~x, ~y, ~f,
1, 3, 'a',
2, 4, 'b'
)
dtx2
#> # A data.trame: [2 × 3]
#> x y f
#> <dbl> <dbl> <chr>
#> 1 1 3 a
#> 2 2 4 b
class(dtx2)
#> [1] "data.trame" "data.frame"
# This is how you specify row names for dtf (data.frame)
dtf(x = 1:3, y = 4:6, .rownames = letters[1:3])
#> x y
#> a 1 4
#> b 2 5
#> c 3 6