Learn R Programming

presenter (version 0.1.2)

get_piped_name: get piped name

Description

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

Usage

get_piped_name(object, default_name = "Table")

Value

string

Arguments

object

an object

default_name

string Attempts to return this string if an error occurs.

Examples

Run this code

#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()

get_piped_name(iris)

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

### 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()

Run the code above in your browser using DataLab