Site icon R-bloggers

R: Functions and environments and a debugging utility, oh my!

[This article was first published on The Data Monkey, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
The Mark Fredrickson blog has a superb post on R functions and environments that’s well worth checking out.

He also includes a handy function for debugging:

> fnpeek < - function(f, name = NULL) {
+ env < - environment(f)
+ if (is.null(name)) {
+ return(ls(envir = env))
+ }
+ if (name %in% ls(envir = env)) {
+ return(get(name, env))
+ }
+ return(NULL)
+ }
> fnpeek(f1)
[1] “n”
> fnpeek(f1, “n”)
[1] 7

To leave a comment for the author, please follow the link and comment on their blog: The Data Monkey.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.