Monday, June 15, 2015

Searching for packages in R. What is the best package to analyse my data?


Many times we want to apply some method or we need an algorithm but we don't have the time to implemented or simply we don't know how to do it. For this situations is good to know how to look for the best or more standardized packages that R offered.

Here is my trick.


  1. Install the package "sos"
  2. Use the function findFn to find the related packages to a given topic.
Let's first install the package sos using the code:


install.packages("sos")
library("sos")

Now we want to know which packages are available for example for "Particle Swarm Optimisation". Let's use the function findFn as follow:

findFn("Particle Swarm Optimisation")
found 18 matches;  retrieving 1 page

Downloaded 10 links in 4 packages.

And automatically we will be redirected to a website with the list of packages founded:



I don't know which is the best package for PSO but at least I know the best scored.




Two-Vector Dictionary in R using "match"


Something common in R is to have two vectors representing a key-value dictionary, for example:


  • Car name
  • Car price

Let's see an example:

We created two vectors using the dataset "car.test.frame" included in the package rpart. The first vector contains the name of the cars (key) and the second vector the list of prices (value). The function "match" is used to look for a couple of cars in the vector of names. If there is a match we get the index in the car_name vector (in our case, 37 and 43). Now we can use the indexes to work with the vector car_price or with the original data frame as a key-value dictionary.

Here is the code:

library(rpart)
str(car.test.frame)

# Get the name of the cars
car_name = row.names(car.test.frame)
car_price = car.test.frame$Price

# List of car's names
cars = c("Volvo 240 4", "Ford Taurus V6")
match(cars, car_name)

# Get the price of the car
car.test.frame[match(cars, car_name),]$Price

# or using the value-vector
car_price[match(cars, car_name)]

Tuesday, June 9, 2015

Problems printing graphical contents / canvas in lastest version of Chrome.


In the last release of Chrome something was wrong printing canvas contents. To see the problem visit the website:

https://developers.google.com/maps/documentation/javascript/examples/circle-simple

  1. Do you see the circles on the map?
  2. Print the page
  3. Observe the differents with the printing version. Do you see the circles? 
If the answer is not, this post solves your problem.


We can solve temporarily the problem until Google launch a new version of Chrome or an update, following the next steps:

  1. Go to: chrome://flags/   (writing "chome://flags/" in your navigation bar)
  2. Deactivate display list 2D canvas.
  3. Restart Chrome (clicking on "Restart" at the bottom of the flags page).
Sorry my Chrome is in German. chrome://flags


Try again printing the previous page and observe the map. Now you should see the circles on the map.