Environments and how to apply them

Adventures with R

I’ve been learning a lot these days. It’s been coming fast and heavy and I have not been able to document much of it. One of the areas I kind of focused on was Environments. I’ve glanced at (but not finished) the chapter Hadley Wickham wrote in his book ‘Advanced R’. One thing that stood out clearly was that environments are data structures just like any other in the language. I will pause there for now.

What I rushed out to post is something I just saw in a post in R Bloggers. The main gist was about loading .RData files safely and this is one area where environments can be put to good use.

Rather than loading the objects from that file into the Workspace (or global environment), just create a new environment with new.env() and load the saved objects into into it by passing it as…

View original post 86 more words

Leave a comment

Filed under Computers & Internet

What a “freak” occurrence taught me about installing R packages

Adventures with R

I was trying to set up a particular Rmarkdown document in such a way that other users on our team, who might not have all the necessary packages installed, could get them automatically.

The first time I tried it out it worked perfectly, but later when I re-knitted the document, this funny window popped up

R package list

I was quite surprised! Oh, what had I done now?

To cut the story short, the answer lies in the R documentation via help('install.packages'):

part documentation for R function

So, argument pkgs (3rd paragraph), when zero-length, is what produced the popup. After installing the missing packages in the first pass of the code I wrote, the vector not_installed was subsequently zero-length. As an example, when one does this…

…our listbox appears.

I therefore decided to throw in a conditional statement to skip the installation step in the event that all required packages are already present:


View original post

Leave a comment

Filed under Uncategorized

Why I decided to become a leader


During one of my first stays in the US I read ‘The rise and fall of the Empires’ by historian Paul Kennedy. This was indeed a superb book. But what I learnt there was also what brought such empires up and down.

What historians have learnt behind the Napoleon story is also the talents of generals and scientists such as Dupleix, Davout, Kleber, Lannes, Lefebvre, Bessières, Champollion, Monge, Berthollet, Fourier and many other ones who have made it possible.

When seeing such a sum of talents and incredible people among the Empire leaders, I had no hesitation, I wanted to help this Empire grow, make it big and fun and build great achievements alltogether.

  1. GREAT LEADERS : I have realized along playing the Empire EK game how brilliant and thorough were many of my new friends, who have taught me so much. And they are both reactive…

View original post 254 more words

Leave a comment

Filed under Uncategorized

Dancing between character vectors and formula objects

Adventures with R

I was determined to exactly reproduce a composite box-and-whisker plot that I had been seeing in the book Introduction to Statistical Learning. The data are from a set of 3,000 observations called Smarket that is found in the R package that goes with the book, known as ISLR. It’s a pretty simple plot:

3 boxplots of stock market data

First, after loading the package with library(ISLR), one may want to take a cursory look at the data frame, which has 9 variable columns, using View(head(Smarket)).

I was able to successfully put together the plot with this code:

I realised, however, that I was seriously violating the DRY principle, so I tried to come up with a function instead. I struggled a bit with this because I didn’t know how to supply a character vector argument and place it into the “formula” bit that is required as the first argument…

View original post 110 more words

Leave a comment

Filed under Uncategorized

Grace is the ‘Jack’ of all Trades.

Indeed, with God’s help we can achieve a lot in a short time!

Believe. Aspire. Experience.


This is how people work without grace. Picture this.
A certain man desires to change the tyre of his car so he proceeds to removing the bolts in the tyre. He is done but now he needs to lift the car up a bit to successfully​ remove the deflated tyre. So he seeks the assistance of two friends, both muscular.


They proceed to lift the car from the back while he removes the tyre. They lift the car up again and he inserts the new tyre, inserts the bolts and the car is ready. Everyone is sweating profusely.


Now picture a man with grace. He wants to remove the tyre, he unbolts the tyre from the hinges and uses a simple jack to lift the car up, removes the tyre and replaces it. Simple.

The jack in this message is GRACE.


Hard work is good and admirable but hard work…

View original post 79 more words

1 Comment

Filed under Uncategorized