Showing posts with label R. Show all posts
Showing posts with label R. Show all posts

Thursday, November 14, 2013

Install R Package without access as root

Operate R under unix system that means you are merely a single user on this SUPER computer. As a unix rookie ( ya indeed I am ) I didn't know I can't install R package but through the root access. Fortunately, I still find a way to go through it on google it!

Check your R to find the path of the R library

> .libPaths()
"/usr/lib/R/library"  "/usr/share/R/library"

This is what appears originally. Then you can make some adjustment with the path of library first, suppose you did install package through

$R CMD INSTALL -l lib/R lib/'packagename'.tar.gz

then it is instantly install in your predestined folder

/lib/R

Then in that folder you have your package to be installed. In case of that, do this in R

> library(packagename, lib.loc="~/lib/R")

Then it's done! Otherwise, there is another way by change the R_LIB in ./cshrc (or ./bashrc) by edit the alias in ./cshrc by the following

if ($?R_LIBS) then
   setenv R_LIBS~/lib/R:$R_LIBS
else
   setenv R_LIBS~/lib/R
endif 

And then source the new edited ./cshrc then

> .libPaths()
"~/lib/R" "/usr/lib/R/library"  "/usr/share/R/library"

you are done!



Thursday, November 7, 2013

R繪圖 -- map plotting

Map plotting needs shape file to do the job; however, it might not be an easy job to do. There are plenty of shape file but you do not have the freedom to adjust the region with your own perference. Therefore, addland(), a function from R package clim.pact is quite a surprise to the map plotting.

FYI, clim.pact is not on CRAN, so you have to downlad through its achieve page. Particularly, if you are a window user, then you will have to install Rtools before you pack "tar.gz" file in R. Check the website below, if you need it.

http://cran.r-project.org/bin/windows/Rtools/

After installing Rtools, then you can unpack your clim.pact by the following comment

install.packages(" path to your clim.pact.tar.gz ", repos=NULL, type="source")

library(clim.pact)
plot(c(117,123),c(21,27),type="n")
addland()
grid()



So easy! What a surprise!