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:
- arduino vs raspberry py
- creating new environments and the use of the attach() function
- calling functions with the same name from different packages using the namespace
Plot.ly is a web service that allows you to host your plots online and share them with friends/coworkers/students/etc.
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 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:
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:
For instance, in any part of your code you can call the lhs in tgp by writing