this function captures the name of an object piped into a function, and returns as a string. Powers the automatic naming found in presenter.

get_piped_name(object, default_name = "Table")

Arguments

object

an object

default_name

string Attempts to return this string if an error occurs.

Value

string

Examples


#necessary to specify this option when using get_piped_name in knitr
options(rlang_trace_top_env = rlang::current_env())


### works if the object is piped or given as an argument
iris %>%
get_piped_name()
#> [1] "iris"

get_piped_name(iris)
#> [1] "iris"

### can even extract name from multistep pipes
iris %>%
dplyr::select(1:3) %>%
get_piped_name()
#> [1] "iris"

### can be placed inside other functions to capture the name and save it

find_name <- function(x){
 get_piped_name() -> new_name

 new_name
}

iris %>%
dplyr:select(1:3) %>%
find_name()
#> [1] "iris"