The R user group at ICL

At ICL, we recently started an informal R user group. We meet up every Thursday and discuss about old and new R packages, problems to solve, tricks, good and bad coding habits and much more.

Last Thursday we had an unusual session in which we did not only talk about R but also web services and hardware devices that could be useful:

  1. plot.ly
  2. arduino vs raspberry py
  3. creating new environments and the use of the attach() function
  4. calling functions with the same name from different packages using the namespace

PLOT.LY

Plot.ly is a web service that allows you to host your plots online and share them with friends/coworkers/students/etc.

ARDUINO vs RASPBERRY PY

Arduino is micro-controller, an open-source electronics platform based on easy-to-use hardware and software. It’s intended for anyone making interactive projects.

The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse.

CREATING NEW ENVIRONMENTS AND THE USE OF ATTACH()

When a data.frame is loaded in the current environment, its columns can be loaded as variables using the function attach().

a <- data.frame( "b"=c(1,2,3), "c"=c(4,5,6), "d"=c(7,8,9) )
# by default b, c and d are not visible
b

Error: object 'b' not found
# if we attach(a)...  b, c and d become visible
attach(a)
b

[1] 1 2 3

The same can also be done by using the new.env() command.

CALLING FUNCTIONS VIA NAMESPACE

Have you ever used two functions with the same name, belonging to two different packages?

Here is an example:

library(tgp)
library(arules)

Both of these packages have an object called “lhs”.

When you load arules after tgp, the lhs function in tgp is masked by the lhs in arules. How can you keep using both function without reloading the libraries?

The answer is: use the name space!

Every package has a set of visible functions that can be called without ambiguity by using the following strategy:

name_of_package::name_of_function

For instance, in any part of your code you can call the lhs in tgp by writing

tgp::lhs
Advertisements
This entry was posted in User Groups and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s