At this point these notes on R and statistics are mostly to myself. Hopefully over time they will evolve into something that can be more generally useful.
Friday, January 24, 2014
Mimicking Object-Oriented Behavior with R Functions (that is Closures)
Actually, there is already a number of ways and packages object-oriented semantics implemented in R. It is nicely summarize in the Table 1 of this article. Let's assume for a moment this diversity of object-oriented approaches in R is not enough. There is an unbearable urge to implement yet another one. Well... let's exploit the fact that functions in R are not functions in a C++ or even Python sense. They are closures. Put in a simple terms it is a function that packaged up with some state. That state (environment in case of R) may contain variables and functions.
A couple of other posts on a somewhat relevant topic that I may suggest are here and here.
Monday, December 16, 2013
Updating values in hierarchical lists
How to parse and update a hierarchical list using an elegant single command? A lot of things can be done with a single command in R. This (after a few considerations) turned out not an exception either.
Friday, December 6, 2013
Fixing the blurry R fonts caused by DPI scaling on Windows 7
R does not play well with high DPI scaling on Windows 7. Fonts look blurry on my 27 inch WHDQ monitor with 150% DPI scaling. Fixing that for 32-bit R was easy. Go to the properties of C:\Program Files\R\R-3.0.2\bin\i386\Rgui.exe. Note, you may need to replace the R version number in that path. Then open the "Compatibility" tab check the box "Disable display scaling on high DPI settings" and you are done. Once you try to do the same for 64-bit counterpart C:\Program Files\R\R-3.0.2\bin\x64\Rgui.exe you'll see the grayed out check box that can not be altered. The solutions requires editing the registry and is described here
http://superuser.com/questions/355915/vista-dpi-scaling-cannot-disable-dpi-scaling-for-wireshark/355953#355953?s=97656833-4e08-4a55-8773-1fe68b5fca77
Brief instructons.
http://superuser.com/questions/355915/vista-dpi-scaling-cannot-disable-dpi-scaling-for-wireshark/355953#355953?s=97656833-4e08-4a55-8773-1fe68b5fca77
Brief instructons.
Go to HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers Most likely you'll already see a setting for 32-bit Rgui.exe Make a similar one by right clicking on the "Layer" and add new string value. Name: C:\Program Files\R\R-3.0.2\bin\x64\Rgui.exe Type: REG_SZ Data: HIGHDPIAWARE
Thursday, November 21, 2013
Saturday, November 16, 2013
Exploring S4 Objects in R
Looking what is inside of a particular method.
Method - spectra
Class - MSnExp
If method is exported (check NAMESPACE) then this will work.
getMethod("spectra","MSnExp")
Method Definition:
function (object)
{
sl <- as.list(assayData(object))
fnames <- featureNames(object)
return(sl[fnames])
}
Signatures:
object
target "MSnExp"
defined "MSnExp"
Showing slots for a given class
showClass("MSnExp")
showMethods(classes="MSnExp", where="package:MSnbase")
Debugging
trace(show, tracer=browser, signature=c(x="eSet"), where=getNamespace("Biobase"))
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.
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
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
Subscribe to:
Posts (Atom)
Checking font availability on Mac fc-list : family | grep "Fira Code" or system_profiler -json SPFontsDataType | grep \...
-
http://www.liacs.nl/~hoogeboo/mcb/nature_primer.html
-
E.g. we have a list of dictionaries x = [{'a':1,'b':3}, {'a':3,'b':2}, {'a':2,'b':1}] x....