Last active
August 29, 2015 14:05
-
-
Save charlesbmi/72dee33eb1edf1d41e30 to your computer and use it in GitHub Desktop.
Function to print variable names and values. Useful for debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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