null_replace: Create a null_replace node.

View source: R/null_replace.R

null_replaceR Documentation

Create a null_replace node.

Description

Replace NA/NULL is specified columns with the given replacement value.

Usage

null_replace(src, cols, value, ..., note_col = NULL, env = parent.frame())

Arguments

src

relop or data.frame data source.

cols

character, columns to work on.

value

scalar, value to write.

...

force later arguments to bind by name.

note_col

character, if not NULL record number of columns altered per-row in this column.

env

environment to look to.

Value

null_replace node or data.frame.

See Also

count_null_cols, mark_null_cols

Examples


if (requireNamespace("DBI", quietly = TRUE) && requireNamespace("RSQLite", quietly = TRUE)) {
  my_db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
  d1 <- rq_copy_to(my_db, 'd1',
                    data.frame(A = c(NA, 2, 3, NA), B = c(3, NA, 4, NA)))
  optree <- null_replace(d1, qc(A, B),
                         0.0, note_col = "alterations")
  cat(format(optree))
  sql <- to_sql(optree, my_db)
  cat(sql)
  print(DBI::dbGetQuery(my_db, sql))
  DBI::dbDisconnect(my_db)
}


rquery documentation built on Aug. 20, 2023, 9:06 a.m.