# Create a unite block
new_unite_block()
if (interactive()) {
# Basic usage - combine first and last name
library(blockr.core)
people_data <- data.frame(
first_name = c("John", "Jane", "Bob"),
last_name = c("Doe", "Smith", "Johnson"),
age = c(30, 25, 35)
)
serve(
new_unite_block(
col = "full_name",
cols = c("first_name", "last_name"),
sep = " "
),
data = list(data = people_data)
)
# With custom separator
serve(
new_unite_block(
col = "id",
cols = c("first_name", "last_name"),
sep = "-",
remove = TRUE
),
data = list(data = people_data)
)
# With NA removal
data_with_na <- data.frame(
prefix = c("Dr.", NA, "Prof."),
first = c("John", "Jane", "Bob"),
last = c("Doe", "Smith", "Johnson")
)
serve(
new_unite_block(
col = "full_name",
cols = c("prefix", "first", "last"),
sep = " ",
na.rm = TRUE
),
data = list(data = data_with_na)
)
}
Run the code above in your browser using DataLab