{
xs <- quos(...)
tibble_quos(xs, .rows, .name_repair)
}
Mini-Lecture 8
Smith College
2024-09-26
map()?if
map()was created as the easier alternative to all theapply()s, why are there so many variations of it??
map() always returns a list“Run the following code in your head, then confirm the result by running the code.
–Hadley Wickham (p. 116)

{
col_names <- given_col_names <- names2(xs)
empty_col_names <- which(col_names == "")
col_names[empty_col_names] <- names(quos_auto_name(xs[empty_col_names]))
lengths <- rep_along(xs, 0L)
output <- rep_along(xs, list(NULL))
env <- new_environment()
mask <- new_data_mask_with_data(env)
first_size <- .rows
for (j in seq_along(xs)) {
res <- eval_tidy(xs[[j]], mask)
if (!is.null(res)) {
if (single_row) {
if (vec_is(res)) {
if (vec_size(res) != 1) {
abort_tibble_row_size_one(j, given_col_names[[j]],
vec_size(res))
}
}
else {
res <- list(res)
}
}
else {
res <- check_valid_col(res, col_names[[j]], j,
call)
lengths[[j]] <- current_size <- vec_size(res)
if (is.null(first_size)) {
first_size <- current_size
}
else if (first_size == 1L && current_size !=
1L) {
idx_to_fix <- seq2(1L, j - 1L)
output[idx_to_fix] <- fixed_output <- map(output[idx_to_fix],
vec_recycle, current_size)
map2(output[idx_to_fix], col_names[idx_to_fix],
add_to_env2, env = env)
first_size <- current_size
}
else {
res <- vectbl_recycle_rows(res, first_size,
j, given_col_names[[j]], call)
}
}
output[[j]] <- res
col_names[[j]] <- add_to_env2(res, given_col_names[[j]],
col_names[[j]], env)
}
}
names(output) <- col_names
is_null <- map_lgl(output, is.null)
output <- output[!is_null]
output <- splice_dfs(output)
output <- set_repaired_names(output, repair_hint = TRUE,
.name_repair = .name_repair, call = call)
new_tibble(output, nrow = first_size %||% 0L)
}
Lab #6: Functions
Pull request posted
Reading quiz on Moodle

SDS 410