<- function(){
hi_wrld "hello world"
}
hi_wrld()
[1] "hello world"
KIND learning network training materials by KIND learning network is licensed under CC BY-SA 4.0
June 18, 2024
function
[1] 20.77928 49.68058 -94.69800 23.20281
[1] 3 7 -14 3
if
/else
Vectorize
lapply
/ purrr::map
with Vectorize
{{}}
so
Error in dplyr::summarise(mtcars, average = round(mean(column))) :
ℹ In argument: `average = round(mean(column))`.
Caused by error:
! object 'hp' not found
object ‘hp’ not found
mtcars$hp
/ mtcars |> select(hp)
hp
like an object, and R figures out the scope etc for ushp
{{}}
carmo_woo <- function(column){
mtcars |>
dplyr::summarise(average = round(mean({{column}})))
}
carmo_woo(hp)
average
1 147
{{}}
as a purely empirical fix{{}}
defuses and injects the column name!!enquo(var)