Thursday, 17 December 2015

Appending Items to List in R

A very common programming problem is that a function must return a list of objects (itmes like trees...).
In R, we can do something like the following:

func_????? <- function ( ... )
{
    ret_TreeList = list()

    for(i in 1: ?????)
    {
        if(...)
        {
             ret_TreeList[[i]] = something
        }
        else(...)
        {
             ret_TreeList[[i]] = something else
        } 
        
    }

    return(ret_TreeList)
}

Then we cna use it like this:

>TreeList = func_?????(...)
>TreeList[3]

Hope it helps ;-}

Wednesday, 16 December 2015

Install R packages Removed from CRAN (from the source)

I need to use some really useful R packages but unfortunately they are removed from CRAN which means I cannot just install.packages(...) from the cloud and I must install it from the source.

There are two ways of doing this:

(1)
library(devtools)
install_url('http://cran.r-project.org/src/contrib/Archive/dynamo/dynamo_0.1.3.tar.gz')
install_url('http://cran.r-project.org/src/contrib/Archive/gafit/gafit_0.4.tar.gz')

(2) Which I prefer!!
Download the package source first and then:
install.packages('/path/dynamo_0.1.3.tar.gz', type = 'source')

ref:
http://stackoverflow.com/questions/18655976/how-to-install-the-package-that-has-been-removed-from-the-cran-repository-in-r-e

Sunday, 13 December 2015

Where is to find the bodyfat dataset?

When trying some old (even not so old) examples using R package mboost, the dataset "bodyfat" cannot be loaded.

> data("bodyfat", package = "mboost")
Warning message:

In data("bodyfat", package = "mboost") : data set ‘bodyfat’ not found

Many famous examples are still like this, like
Yanchang Zhao's book: “R and Data Mining: Examples and Case Studies”

==============================================================

The data is provided in package TH.data, but no longer in package mboost.

To use the data, run code below.

data("bodyfat", package="TH.data")