Thursday, November 7, 2013

Where are the R libraries?

on Mac
/Library/Frameworks/R.framework/Versions/3.0/Resources/library
on Win
c:/Users/vlad/R/win-library/3.0

Thursday, November 22, 2012

Passing-by-reference in R

collection of links to debates/tricks on passing-by-reference in R. http://stackoverflow.com/questions/2603184/r-pass-by-reference
http://www.stat.berkeley.edu/~paciorek/computingTips/Pointers_passing_reference_.html
https://stat.ethz.ch/pipermail/r-devel/2009-January/051899.html
http://homepage.stat.uiowa.edu/~luke/R/references.html
http://r.789695.n4.nabble.com/Pass-By-Value-Questions-td2331565.html

My take on that is to use new Reference Classes if there is a need for complex mutable objects.
Use of environments to pass-by-reference is considered as a hack.
E.g. (from Robert Gentleman's book)
e1 = new.env()
f = function(x) {x+z}
enironment(f) = e1
e1$z = 10
f(1)
Output is 11
Note, however, after deleting e1, f does not go away.
rm(e1)
f is still around

Second point is to take a look at data.frame by pass-by-reference using "ref" and "plyr" packages.

Sunday, October 28, 2012

customizing R


On windows:
C:\Program Files\R\R-2.15.1\etc\Rprofile.site


My Rprofile with added custom color schemes

# Things you might want to change

# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")

# set the default help type
# options(help_type="text")
  options(help_type="html")

# set a site library
# .Library.site <- file.path(chartr("\\", "/", R.home()), "site-library")

# set a CRAN mirror
# local({r <- getOption("repos")
#       r["CRAN"] <- "http://my.local.cran"
#       options(repos=r)})

# Give a fortune cookie, but only to interactive sessions
# (This would need the fortunes package to be installed.)
if (interactive()) {
   fortunes::fortune()
   
   #---- custom color schemes
   library(grDevices)
   blue.colors = colorRampPalette(RColorBrewer::brewer.pal(9,"Blues"))
   jet.colors = colorRampPalette(c("blue","#007FFF","cyan","#7FFF7F","yellow","#FF7F00","red"))
   blackBody.colors = colorRampPalette(c("black", "red", "orange","yellow","lightyellow"),space="rgb")
}


Wednesday, October 24, 2012

Struggling with mounting shared directory on VirtualBox

some good info

1) Run as sudo VBoxLinuxAdditions.run
1a) sudo sh ./VBoxLinuxAdditions.run
2) make directory e.g. HostData in /home/d3m629/ folder
3) Set what is shared is VirtualBox itself
4) sudo mount -t vboxsf -o uid=MYUSERNAME Google_Drive ~/HostData
5) then add this to /etc/init.d/rc.local or ? /etc/rc.local
5a) mount -t vboxsf -o uid=MYUSERNAME Google_Drive /home/MYUSERNAME/HostData
6) enter HostData directory and bookmark it for easy access.

Obviously MYUSERNAME has to be replaced with the actual one.


Another thing to do after installing Ubuntu on VirtualBox running on Mac is ...
Keyboard Layout -> Options -> Alt/Win Key behavior ->  Control is mapped to Win keys (and the usual Ctrl keys)

In case of Xubuntu.
Run
setxkbmap -option altwin:ctrl_win
To make the change permanent
echo -option altwin:ctrl_win >>~/.Xkbmap
original doc


Changing themes for Unity

Tuesday, March 20, 2012

informative discussion on variable scope control in R

http://stackoverflow.com/questions/6216968/r-force-local-scope
This somehow magically works, but I need to comprehend.
environment(fun) = parent.env(environment(fun))

Saturday, March 10, 2012

my experience with installing Rgraphviz on Ubuntu (10.10)

make sure libgraphviz-dev is installed. It is needed for some header files (e.g. gvc.h)
then
biocLite("Rgraphviz", configure.args=c("--with-graphviz=/usr"))
the reason is that at least on my computer the dot program was in /usr/bin, but not in /usr/local/bin as Rgraphviz defaults

Tuesday, December 13, 2011

Accessing SQL Server DB from R on Linux using RODBC package

First of all you'll need to install FreeTDS package.

brew update
brew install unixodbc
brew install freetds
It looks like there is no need to specify --with-unixodbc any more.


I would add only that I had to edit not
/etc/odbcinst.ini
but
/usr/local/etc/odbcinst.ini,

On Linux it looks like this
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/lib/odbc/libtdsodbc.so
Setup = /usr/lib/odbc/libtdsS.so
Threading = 1
CPTimeout =
CPReuse = 
FileUsage = 1

On Mac paths are a bit different
[FreeTDS]
Description = TDS driver (Sybase/MS SQL)
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsS.so
Threading = 1
CPTimeout =
CPReuse = 
FileUsage = 1


then it worked just fine.
Here is a sample code:
library(RODBC)
# replace server.name, database.name, user.id, password and T_my_table correspondingly
con <- odbcDriverConnect("DRIVER={FreeTDS};SERVER=server.name;DATABASE=database.name;UID=user.id;PWD=password;")
strSql <- "select * from T_my_table"
x <- sqlQuery(con, strSql)
close(con)
cat(x)

Checking font availability on Mac   fc-list : family | grep "Fira Code"   or   system_profiler -json SPFontsDataType | grep \...