Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Shiny

You're reading from   Learning Shiny Make the most of R's dynamic capabilities and implement web applications with Shiny

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781785280900
Length 246 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Hernan Resnizky Hernan Resnizky
Author Profile Icon Hernan Resnizky
Hernan Resnizky
Hernan Resnizky Hernan Resnizky
Author Profile Icon Hernan Resnizky
Hernan Resnizky
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Introducing R, RStudio, and Shiny FREE CHAPTER 2. First Steps towards Programming in R 3. An Introduction to Data Processing in R 4. Shiny Structure – Reactivity Concepts 5. Shiny in Depth – A Deep Dive into Shiny's World 6. Using R's Visualization Alternatives in Shiny 7. Advanced Functions in Shiny 8. Shiny and HTML/JavaScript 9. Interactive Graphics in Shiny 10. Sharing Applications 11. From White Paper to a Full Application Index

Control structures in R

Control structures in computer programming are statements that decide the execution (or not) of certain pieces of code. In while and if, they are based on a condition that evaluates to TRUE or FALSE, and in for, the statement is executed for every element of the input sequence.

In R, all the control structures have the same coding pattern, as follows:

control_structure(condition or sequence){code block}

The if...else block

The following is a small example of an if...else block in R. You can play with it by changing the value of a:

> a <- 5
> if(a > 0){print("a is greater than 0")} else
+ { print("a is smaller than 0")}
[1] "a is greater than 0"

Note

The else clause must start in the same line where the if clause ends.

With an else...if statement, it would be:

> a <- 10
> if(a < 0 ){
+   print("a is smaller than 0")} else if(a >= 0 & a <= 5)
+     { print("a is between 0 and 5")} else
+  ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime