Predictive Hacks

How to Draw Flow Diagrams in R

The “flow” package visualizes as flow diagrams the logic of functions, expressions, or scripts. Let’s take an example of a function that checks if a number is a prime or not.

is_prime <- function(num) {
   if (num == 2) {
      TRUE
   } else if (any(num %% 2:(num-1) == 0)) {
      FALSE
   } else { 
      TRUE
   }
}
 
is_prime(997)
 
[1] TRUE

We can get the flow diagram by running:

library(flow)
flow_view(is_prime)
 
How to Draw Flow Diagrams in R 1

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Photo by NordWood Themes on Unsplash
Miscellaneous

How To Manage Multiple Screen Sessions

Linux’s Screen lets you run terminal applications to a Server in the background even if you disconnect from the ssh connection.

python exception
Python

Exceptions in Python

In this tutorial, we will provide you with an example of exception handling in Python. For simplicity, we will work