(i in seq_along(repos)) { v[[i]] <- get_domain(repos[[i]]) } v ## [1] "sourceforge" "nasa" "github" v <- c() repos <- c() for (i in 1:length(repos)) { v[[i]] <- get_domain(repos[[r]]) } ## Error in get_component_(x, 1): Not compatible with STRSXP: [type=NULL]. 12 / 47
that is not the first argument of the function, use anonymous functions. v1 <- c(1, 2, 3) my_add <- function(x = 1, y = 2) { x + y } map_dbl(v1, ~ my_add(x = 1, y = .)) ## [1] 2 3 4 19 / 47
code form the back end (dplyr, dbplyr, dtplyr) Becareful, NSE makes functions not referentially transparent, meaning if you replace the value to a function with an equlivilant object, you get a different result 33 / 47
beginning of the talk? # I just took Hadley's example my_mutate <- function(df, var) { n <- 10 var <- rlang::enexpr(var) dplyr::mutate(df, !!var) } df <- tibble::tibble(x = 1) n <- 100 my_mutate(df, x + n) ## # A tibble: 1 x 2 ## x `x + n` ## <dbl> <dbl> ## 1 1 11 43 / 47