Thursday, November 28, 2013

Add python to Windows 7 DOS Path

Run Python from Window 7 DOS is not as straightforward as in Mac Os X.  You may meet this prompt if you haven't set the python path in DOS:

 C:\Users\dz2t >python
'python' is not recognized as an internal or external command,
operable program or batch file.

Here is a way to solve this problem:
click: Start --> Control Panel --> System and Security -->System

On the left side of the screen, you should be able to see 'Advanced system settings', and then click it.
Then at the bottom click 'Environment Variables'. In the System variables box, find and click something like 'Path    C:....'. Finally, in the pop 'Edit System Variable' box, you need to add the python path to the 'Variable value'. Usually add this text to the end of the box:

;C:\Python33;C:\Python33\scripts

Then from the DOS window you can evoke python directly.


Tuesday, November 19, 2013

Setting R Path in Mac OS for Latex

There's a nice latex() function from R package 'Hmisc' to generate LaTex tables automatically,  but the function might not work for Mac OS X platform due to the path environmental variables in R isn’t set to include the path to TeX binaries.

Here, we can see that the R path does not include the path to TeX binaries:
> Sys.getenv("PATH")
[1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
 

So, if you try to call the latex() function, it will give an error message like that:

library(Hmisc) # Load Hmisc to load latex()
x <- matrix(1:6, nrow=2, dimnames=list(c('a','b'),c('c','d','this that'))) # From latex() examples
latex(x)
error /bin/sh: latex: command not found
error in system(cmd, intern = TRUE, wait = TRUE) :
error in running command
sh: xdvi: command not found
To add the Tex PATH into the R envirnment, following my last blog to create .Rprofile and add the following command to the file:
Sys.setenv(PATH=paste(Sys.getenv("PATH"),"/usr/texbin",sep=":"))
After reboot R, you will find the tex path was added.
> Sys.getenv("PATH")
[1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin"
 

Monday, November 18, 2013

Add default packages in R

Checking around seems there's no a detail description on how to add your frequent-using-packages as your default loadings in R. Here is an easy way to make it (as least works for MAC OS).

By launching R you will see this message:
----------------------------------------------------------------
...
[R.app GUI 1.61 (6492) x86_64-apple-darwin10.8.0]

[Workspace restored from /Users/dz2t/.RData]
[History restored from /Users/dz2t/.Rapp.history]


----------------------------------------------------------------

Here, the directory ''/Users/dz2t/" is the HOME folder that R will search and run when it's initiating. To load a set of default stuffs (not only packages), what you need to do is just to create a ".Rprofile" file in this directory. I use the mac terminal to create this file and I guess you can also use any text editor to do so and save it under an exact name: .Rprofile. And finally the most important and also a easy thing next to do is to list the libraries in the file and save it like that:
----------------------------------------------------------------
options(width=65, digits=5)
options(defaultPackages=c(getOption("defaultPackages"), "ggplot2", "mice", "grid", "gtools",
                        "gdata", "pscl", "zoo", "car", "DirichletReg", "plyr", "bestglm", "tree",
                        "betareg", "psych", "gee", "ggdendro", "sas7bdat", "reshape2"))
s <- base::summary
h <- utils::head
n <- base::names
.First<-function() cat("\n  Welcome to R!\n\n")
.Last<-function() cat("\n  See you next time! \n\n")

----------------------------------------------------------------
where   s <- base::summary is a shortcut for summary(), which means you can put anything you want in this file and R will load and run it before your start work.


Tuesday, November 12, 2013

Here is the Zen

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.

zz from here