Teach Yourself How to Create Functions in R

[This article was first published on Brock's Data Adventure » R, 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.

As you can tell from my previous posts, I am diving in head first into learning how to program (and simplify) my analytical life using R.  I have always learned by example and have never really prospered from the “learn from scratch” school of thought.  As I follow along with some other fellow R programmers, I find that they often use functions.  Intuitively I understand what they are and why the are awesome, yet I rarely find myself every thinking to employ them.

One reason is that I simply don’t yet fully grasp how to catch errors and debug them efficiently.  In addition, I am a very sloppy coder and don’t want to create anything “too complicated” since I am just starting out.  However, I recently was introduced to a neat little trick and I wanted to share.

Say there is a function that you often use but finding yourself wanting to make a personal change to.  Simply type the function name into the command line without any arguments!

For example:

library(gmodels)
CrossTable

For example, I currently am trying to find a quick way to automate professional- looking crosstabs that I would feel comfortable using in the appendix of a survey research project on campus.  I really like the CrossTable function inside the gmodels package, but when Sweaving the output, the size is rediculous!  Even when it print’s to the console, you can see how large it prints to other things.  Not that I am capable of figuring out how to change this quite yet, it is still good as a newbie to R to see how the function was programmed, and presumably, how to improve my R coding skills.

As an aside, I recently added my blogs post to the R-bloggers feed.  If you stumble across my posts and are too trying to learn R, you would be well off to subscribe to the RSS feed.  The link to the feed is https://www.r-bloggers.com/.


Filed under: R Tagged: R, R functions, Sweave

To leave a comment for the author, please follow the link and comment on their blog: Brock's Data Adventure » R.

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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)