-
Book Overview & Buying
-
Table Of Contents
Learning RStudio for R Statistical Computing
Functions are an important tool of programming. Functions allow you to separate a set of operations from the main script and give them a useful name. It also allows you to define variables that are otherwise invisible to the rest of the script; in the language of software developers, this is called scoping. Finally, functions can be shared; once you've developed a cool new procedure that takes a data set and creates the most awesome plot, why not write a function for it and share it with your friends?
RStudio has two convenient features for function writing (not discussed earlier in this book)—automatic function extraction and function code retrieval.
RStudio's function extraction feature allows you to select a piece of code and wrap it in a function definition, which can be stored separately for re-use. Here's a simple example. Suppose we've found this procedure that computes one of the roots of a quadratic equation and we've written...
Change the font size
Change margin width
Change background colour