insert
, update
, or delete
rows from a faketables
object
Arguments
- faketable
A
faketable()
object- data
insert
: A data.frame to add to the data in thefaketable()
object. If it does not already have a primary key column as specified intable_def()
, one will be created and primary keys will be generated.update
: A data.frame with a primary key column as specified intable_def()
with primary key values already present in the data.delete
: Either a character vector of values from the primary key column as specified intable_def()
or a data.frame of rows to remove with that vector as a column.
Value
A faketable()
object
Details
update
: This method cannot add new columns or change the class of existing columns because it is based ondplyr::rows_update()
.
Examples
faketable <- faketable(
mtcars,
table_def(
col_def(
name = 'mpg',
input = input_call(
fun = shiny::textInput,
args = list(label = NULL, placeholder = 'mpg')
),
cast = as.numeric,
width = 3,
display_name = 'MPG'
)
)
)
# insert
# to insert a copy of the first row of `mtcars`
faketable <- insert(faketable, utils::head(mtcars, 1))
# update
# to update 'mpg' to only whole numbers
faketable <- update(faketable, dplyr::mutate(faketable@.data, 'mpg' = round(mpg)))
# delete
# to delete the first six rows of the data where the primary key column is `rowId`
rows_to_delete <- utils::head(faketable@.data)
faketable <- delete(faketable, rows_to_delete$.rowId)
# OR
faketable <- delete(faketable, rows_to_delete)
faketable@data
#> # A tibble: 27 × 11
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 14 8 360 245 3.21 3.57 15.8 0 0 3 4
#> 2 24 4 147. 62 3.69 3.19 20 1 0 4 2
#> 3 23 4 141. 95 3.92 3.15 22.9 1 0 4 2
#> 4 19 6 168. 123 3.92 3.44 18.3 1 0 4 4
#> 5 18 6 168. 123 3.92 3.44 18.9 1 0 4 4
#> 6 16 8 276. 180 3.07 4.07 17.4 0 0 3 3
#> 7 17 8 276. 180 3.07 3.73 17.6 0 0 3 3
#> 8 15 8 276. 180 3.07 3.78 18 0 0 3 3
#> 9 10 8 472 205 2.93 5.25 18.0 0 0 3 4
#> 10 10 8 460 215 3 5.42 17.8 0 0 3 4
#> # ℹ 17 more rows