Package 'dcmodifydt'

Title: Modification Rules on 'data.table'
Description: Apply 'dcmodify' rules on a 'data.table', code generated is optimized for changing a data.table in place / by reference.
Authors: Edwin de Jonge [aut, cre]
Maintainer: Edwin de Jonge <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0.9000
Built: 2024-12-22 02:46:33 UTC
Source: https://github.com/data-cleaning/dcmodifydt

Help Index


Dump data.table modification script

Description

Dump data.table modification script

Usage

dump_dt(x, name = "dat", file = stdout())

Arguments

x

dcmodify::modifier() object with the modification rules

name

character name of data.table to be used.

file

where should the generated file be written?

Examples

library(dcmodify)

m <- modifier( if (age > 130) age = 130
               , income[age < 12] <- 0
)

dump_dt(m, "my_data")

Modify records in a data.table

Description

Modify records in a data.table using modification rules specified in a modifier object.

Usage

## S4 method for signature 'data.table,modifier'
modify(dat, x, copy = NULL, sequential = TRUE, ...)

Arguments

dat

data.table() object

x

dcmodify::modifier object.

copy

if TRUE modify copy of table.

sequential

if TRUE (default), steps will be executed in sequence, so order matters.

...

unused

Details

This is a more efficient implementation then coercing the data.table to a data.frame and use that implementation.

See Also

Other modify: setmodify()

Examples

library(data.table)

m <- modifier( if (age > 130) age = 130
             , income[age < 12] <- 0
             )

dat <- fread(text =
"age, income
 140,  300
  11, 2000
  25, 3000"
)

# modify a copy of the data
dat_m <- modify(dat, m, copy = TRUE)
print(dat_m)

# the data it self
setmodify(dat, m)
print(dat)

modifies data.table in place

Description

modifies data.table in place, alias for modify with copy=TRUE and sequential=TRUE. It follows the naming convention in data.table to prefix methods that change objects (byreference) with set.

Usage

setmodify(dat, x, ...)

Arguments

dat

data.table() object

x

dcmodify::modifier object.

...

not used

See Also

Other modify: modify,data.table,modifier-method

Examples

library(data.table)

m <- modifier( if (age > 130) age = 130
             , income[age < 12] <- 0
             )

dat <- fread(text =
"age, income
 140,  300
  11, 2000
  25, 3000"
)

# modify a copy of the data
dat_m <- modify(dat, m, copy = TRUE)
print(dat_m)

# the data it self
setmodify(dat, m)
print(dat)