Skip to content

Instantly share code, notes, and snippets.

@charlesbmi
Last active August 29, 2015 14:05
Show Gist options
  • Save charlesbmi/72dee33eb1edf1d41e30 to your computer and use it in GitHub Desktop.
Save charlesbmi/72dee33eb1edf1d41e30 to your computer and use it in GitHub Desktop.
Function to print variable names and values. Useful for debugging
pr <- function(...) {
# prints variable names and values
dots <- substitute(list(...))[-1] # remove 1st element, "list"
print(sapply(dots, deparse)) # names
print(paste(list(...))) # values
}
# demo
a <- 1
b <- c(3,5,2)
c <- list(a, a=2)
pr(a,b,c)
# will print
# [1] "a" "b" "c"
# [1] "1" "c(3,5,2)" "list(1, a = 2)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment