Skip to content

Add info about using headliner within a function #66

@rjake

Description

@rjake
library(headliner)

# base R
func <- function(add = 123) {
  fn_env <- new.env()             # create new environment fn_env
  fn_env$x <- add                 # assign to fn_env
  
  headline(
    1, 2, headline = "{x}",
    .envir = fn_env               # use fn_env
  )
}

func()


# use rlang::current_env()
func <- function(add = 123) {
  x <- add                        # assign as normal
  
  headline(
    1, 2, headline = "{x}",
    .envir = rlang::current_env() # use function environment
  )
}

func()

# use rlang::env()
func <- function(add = 123) {
  fn_env <- rlang::env(x = add)   # create environment & assign at same time
  
  headline(
    1, 2, headline = "{x}",
    .envir = fn_env               # use fn_env
  )
}

func()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions