August 28, 2014

Autojump in 12.04 doesn't work

I installed with apt-get, checked out the man page and added . /usr/share/autojump/autojump.sh to my .bashrc, like it says. When I cd around the filesystem, nothing gets added to ~/.local/share/autojump. I then tried adding . /usr/share/autojump/autojump.bash, but that didn't work either.

---

You'll probably want to add the following to your .bashrc:

source /usr/share/autojump/autojump.bash

©

How To Set Up an NFS Mount on Ubuntu 12.04

Author: Etel Sverdlov Published: Sep 17, 2012 Updated: Jun 11, 2014

About NFS (Network File System) Mounts

NFS mounts work to share a directory between several virtual servers. This has the advantage of saving disk space, as the home directory is only kept on one virtual private server, and others can connect to it over the network. When setting up mounts, NFS is most effective for permanent fixtures that should always be accessible.

Setup

An NFS mount is set up between at least two virtual servers. The machine hosting the shared network is called the server, while the ones that connect to it are called ‘clients’.
This tutorial requires 2 servers: one acting as the server and one as the client. We will set up the server machine first, followed by the client. The following IP addresses will refer to each one:
Master: 12.34.56.789
Client: 12.33.44.555
The system should be set up as root. You can access the root user by typing
sudo su-

Setting Up the NFS Server

Step One—Download the Required Software

Start off by using apt-get to install the nfs programs.
apt-get install nfs-kernel-server portmap

Step Two—Export the Shared Directory

The next step is to decide which directory we want to share with the client server. The chosen directory should then be added to the /etc/exports file, which specifies both the directory to be shared and the details of how it is shared.
Suppose we wanted to share two directories: /home and /var/nfs.
Because the /var/nfs/ does not exist, we need to do two things before we can export it.
First, we need to create the directory itself:
mkdir /var/nfs/
Second, we should change the ownership of the directory to the user, nobody and the group, no group. These represent the default user through which clients can access a directory shared through NFS.
Go ahead and chown the directory:
chown nobody:nogroup /var/nfs
After completing those steps, it’s time to export the directories to the other VPS:
nano /etc/exports
Add the following lines to the bottom of the file, sharing both directories with the client:
/home           12.33.44.555(rw,sync,no_root_squash,no_subtree_check)
/var/nfs        12.33.44.555(rw,sync,no_subtree_check)
These settings accomplish several tasks:
  • rw: This option allows the client server to both read and write within the shared directory
  • sync: Sync confirms requests to the shared directory only once the changes have been committed.
  • no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger filesystem, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
  • no_root_squash: This phrase allows root to connect to the designated directory
Once you have entered in the settings for each directory, run the following command to export them:
exportfs -a

Setting Up the NFS Client

Step One—Download the Required Software

Start off by using apt-get to install the nfs programs.
apt-get install nfs-common portmap

Step Two—Mount the Directories

Once the programs have been downloaded to the the client server, create the directories that will contain the NFS shared files
mkdir -p /mnt/nfs/home
mkdir -p /mnt/nfs/var/nfs
Then go ahead and mount them
mount 12.34.56.789:/home /mnt/nfs/home
mount 12.34.56.789:/var/nfs /mnt/nfs/var/nfs
You can use the df -h command to check that the directories have been mounted. You will see them last on the list.
df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/sda                20G  948M   19G   5% /
udev                   119M  4.0K  119M   1% /dev
tmpfs                   49M  208K   49M   1% /run
none                   5.0M     0  5.0M   0% /run/lock
none                   122M     0  122M   0% /run/shm
12.34.56.789:/home      20G  948M   19G   5% /mnt/nfs/home
12.34.56.789:/var/nfs   20G  948M   19G   5% /mnt/nfs/var/nfs
Additionally, use the mount command to see the entire list of mounted file systems.
mount
Your list should look something like this:
/dev/sda on / type ext4 (rw,errors=remount-ro,barrier=0) [DOROOT]
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)
12.34.56.789:/home on /mnt/nfs/home type nfs (rw,vers=4,addr= 12.34.56.789,clientaddr=12.33.44.555)
12.34.56.789:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,vers=4,addr=12.34.56.78,clientaddr=12.33.44.555)

Testing the NFS Mount

Once you have successfully mounted your NFS directories, you can test that they work by creating files on the Client and checking their availability on the Server.
Create a file in each directory to try it out:
touch /mnt/nfs/home/example /mnt/nfs/var/nfs/example
You should then be able to find the files on the Server in the /home and /var/nfs directories.
ls /home
ls /var/nfs/
You can ensure that the mount is always active by adding the directories to the fstab file on the client. This will ensure that the mounts start up after the server reboots.
nano /etc/fstab
12.34.56.789:/home  /mnt/nfs/home   nfs      auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
12.34.56.789:/var/nfs  /mnt/nfs/var/nfs   nfs     auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
You can learn more about the fstab options by typing in:
man nfs
Any subsequent restarts will include the NFS mount—although the mount may take a minute to load after the reboot
You can check the mounted directories with the two earlier commands:
df -h
mount

Removing the NFS Mount

Should you decide to remove a directory, you can unmount it using the umount command:
cd
sudo umount /directory name
You can see that the mounts were removed by then looking at the filesystem again.
df -h
You should find your selected mounted directory gone.
©

How do I disable X at boot time so that the system boots in text mode?

For Ubuntu 11.10 and higher
Edit /etc/default/grub with your favorite editor,
sudo nano /etc/default/grub

Find out this line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

Change it to:
GRUB_CMDLINE_LINUX_DEFAULT="text"

Update Grub:
sudo update-grub

No need to remove / disable lightdm upstart conf, it already does that for you.
lightdm.conf
# Check kernel command-line for inhibitors, unless we are being called
        # manually
        for ARG in $(cat /proc/cmdline); do
            if [ "$ARG" = "text" ]; then
                plymouth quit || :
                stop
                exit 0
            fi
        done

You will still be able to use X by typing startx after you logged in.
©

August 20, 2014

Getting Started With R: Some Resources

There are many, many excellent resources for newcomers to R. Here are a few I can personally recommend.

On-Line Introductions and Tutorials

An Introduction to R: In R, run help.start(), then click on "An Introduction to R".
An introduction to many topics. Not very tutorial, however. By Venables, Smith, et al. Also available at http://cran.r-project.org/doc/manuals/R-intro.pdf.
Using R for Data Analysis and Graphics: http://cran.r-project.org/doc/contrib/usingR.pdf
An easy-to-read tutorial. By J. H. Maindonald.
Quick-R for SAS/SPSS/Stata Users: http://www.statmethods.net/
An R language tutorial for people who already know SAS, SPSS, or Stata. By Robert Kabacoff.
Some Hints for the R Beginner: http://www.burns-stat.com/
Click on "Tutorials" to get started with R. By Patrick Burns.

Sources of Help

The R search engine: http://rseek.org/
Looking for something? Start here. This search engine focuses on R-related web sites.
The R Help mailing list: https://stat.ethz.ch/mailman/listinfo/r-help
An incredible amount of Q&A. Got a question? First, search the archives (http://tolstoy.newcastle.edu.au/R/), since it's likely that someone already answered your question. Second, post your question if necessary, but read the posting guide before you do (http://www.r-project.org/posting-guide.html).
Stack overflow: http://stackoverflow.com/questions/tagged/r
Ask a question, get an answer from an expert. Use the "r" tag.
Twitter: http://twitter.com/#search?q=%23rstats
If you can squeeze your question into 140 characters, someone might know the answer. Use the #rstats hashtag.

Books

R in a Nutshell by Joseph Adler (http://www.amazon.com/dp/059680170X)
A combination tutorial and reference book.
A Beginner's Guide to R by Zuur, Ieno, and Meesters (http://www.amazon.com/dp/0387938362)
A quick-start guide for newbies.
Using R for Introductory Statistics by John Verzani (http://www.amazon.com/dp/1584884509)
A good introduction to both R and statistics.
R Graphics by Paul Murrell (http://www.amazon.com/dp/158488486X)
If you want to understand graphics in R, this is the book.
Modern Applied Statistics with S (4th ed.) by Venables and Ripley (http://www.amazon.com/dp/1441930086)
Especially good for anyone who knows statistics and wants to start using R.

©

R: Getting started with R

Main page on R
Don't try to do too much in one session. You might like to just install R and then come back and do further steps such as going through the Venables and Ripley tutorial and installing libraries. Finally you will want to use project directories in which you keep data, scripts and other files pertaining to a particular project.
For a quick start, focus on the items that are marked QUICK START:.

Contents

[hide]

Installing R

Windows, Mac or Linux

QUICK START: To install R, you can go to the CRAN (Comprehensive R Archive Network website) and follow the instructions.
You should consider installing RStudio, a recently released IDE (Integrated Development Environment) for using R that has gained rapid popularity.
You will eventually need to install additional packages which you can do easily whenever your computer is connected to the internet.

Further information

You can get more information on installing R and RStudio at John Fox's website.

Starting to learn R: Tutorials on the Web

Start by working through sample scripts. This is probably the best way to start exploring and enjoying R without getting overwhelmed by long explanations.
After working though sample scripts, you can explore other tutorials:
  1. A list of tutorials recently (January 2012) recommended on the LinkedIn blog The R Project for Statistical Computing:
  2. An annotated list elsewhere on this wiki: R: R tutorials and courses.
  3. An extensive list of on-line books and tutorials is available from the CRAN site.
  4. Chris Green at the University of Washington has an excellent very accessible on-line book: Christopher Green: R Primer
  5. An introductory sample session: http://cran.r-project.org/doc/manuals/R-intro.html#A-sample-session
  6. The very basics from a tutorial at the University of Waterloo.
  7. The first chapter of Venables and Ripley adapted to R VR4: Chapter 1 summary. This is more of an introductory session than a tutorial. It gives a good overview of the potential in using R as well as introducing a number of interesting statistical ideas.
  8. The tutorial that comes with R[1] is extensive but gradually working through it might be the best way to become proficient.
  9. R tutorial at UCLA This is good but takes you through some things you won't really need.
  10. The start of a local tutorial (please contribute)
  11. If you are already familiar with SAS or SPSS you should have a look at Rob Munchen (2007) R for SAS and SPSS Users

Other interesting tutorials on the web

If you find other good tutorials, please add links, preferably with short comments, here
Short introduction to the basic features of R. A good point to start.
Introduction to R with a lot of statistical examples
  • An Introduction to R: Software for Statistical Modelling & Computing 3 by Petra Kuhnert and Bill Venables:
http://cran.r-project.org/doc/contrib/Kuhnert+Venables-R_Course_Notes.zip
Extensive non-technical coverage of R, 364 pages
Reference introductory text for using R.

Script Editors

The built-in editor lacks some desirable features. For example, under Windows, it does not show matching parentheses. You will probably want to get a separate editor.
Recently released RStudio, which is free, provides an integrated environment including a script editor that will probably displace previously available editors.
RStudio has probably superseded previous R editors but for historical completeness one can metion a number of other possibilities, some of which are free. Emacs is very powerful but difficult to learn, Tinn-R (see below) under Windows is easier to install and use but suffers from less than perfect reliability. WinEdt is not expensive (Academic: US$40) and is considered a very good editor with an interface, R-WinEdt designed for R.

Keeping your work

Probably, the ideal way (as of the fall of 2013) to keep output and to perform analyses in a way that is reproducible is to use R Markdown in RStudio.
A more primitive but simple way to keep output and selected graphs so they can eventually become part of a report is to copy and paste output and graphs into a Word file. Graphs can be copied and pasted as 'Windows metafiles' without loss of resolution. Text in the R output window should be pasted with a 'fixed width font' such as Courier New.

Using and installing packages

Many packages come with R. To use them in an R session, you need to load the package. For example to load the MASS package which contains functions and datasets that accompany Venables and Ripley, Modern Applied Statistics with S, you use the command:
> library(MASS)
To get an overview of what's available in MASS, you use:
> library(help=MASS)

Installing additional packages

Some packages are not automatically installed when you install R but they need to be downloaded and installed individually. An important example is the 'car' package that accompanies Fox, Applied Regression. You install it with the R command:
> install.packages("car")
After installing it you load it the same way as a pre-installed package, i.e.
> library(car)
To get information about the package, use:
> library(help = car)
On your own computer, the package needs to be installed only once. On a lab computer you may need to reinstall in each new session.
At this stage, have a look at R basics on the UCLA ATS web site.

Setting up project directories

RStudio provides facilities for managing project directories. If you are working only with R you can organize your work in project directories as follows:
  • Create a directory for your project.
  • Copy a workspace (a .Rdata file) to the directory
  • You can then start R by clicking on the .Rdata file's icon
  • All directory references in the R session will be relative to the project directory. For example, you can read a file 'data.csv' in the directory with
> data <- read.csv('data.csv')

R lessons

Template:Incomplete
Generate links to a set of lessons people can use to learn R. Each lesson should take approximately 1 hour and contain exercises.

R Tip sheets

Exploring more deeply

Exploring much more deeply

This is not up to date. Please help
  • R Portal at UCLA[4]

Courses in specialized areas

Later

Incomplete

Introductions to R

Materials from John Fox

Materials from John Fox

Use stuff from here: Getting Started page on the old math wiki
©

Getting Started with the R Data Analysis Package

Professor Norm Matloff
Dept. of Computer Science
University of California at Davis
Davis, CA 95616
R is a wonderful programming language for statistics and data management, used widely in industry, business, government, medicine and so on. And it's free, an open source product. The S language, of which R is essentially an open source version, won the ACM Software System Award in 1998.

Downloading R:

R is available for Linux, Windows and Mac systems.
You can download R from its home page.
For Ubuntu Linux or other Debian-related OSs, a more direct method is:
% sudo apt-get install r-base

Learning R:

There is a perception among some that R has a steep learning curve, but I disagree. True, R usage has its advanced aspects, but my recommendation is simply, just get started! Start simple, and then refine gradually.
I'll list a few tutorials below (not necessarily the best, just ones I know of). But first, I wish to make a very important point:
"When in doubt, try it out!" That's a slogan I invented to illustrate the point that R's interactive mode allows you to try your own little experiments, the best way to learn. Keep this in mind when you go through the tutorials listed below and in Google.
Here are some resources that I would recommend for learning R:

Advanced R:

R Programming Tools:

One of the most debated topics in R online discussions is that of programming tools for R, of which there are many.
  • I'm not a fan of integrated development environments, but if you like IDEs, there are a number of open source products available:
    • The most popular is undoubtedly RStudio, RStudio, introduced in 2011, and growing rapidly in functionality.
    • For fans of the Eclipse framework, StatET is available, and includes a debugging tool.
    • More established products include JGR, Rcmdr, RKWard.
    • There are a number of plugins for text editors such as Emacs (for which a debugger is available), Vim, gedit, and so on.
    • In the commercial realm, there is one from Revolution Analytics , which also includes a debugging tool.

People you can talk to:

  • There are various mailing lists (start with R-help) shown on the R home page.
  • There are R user groups in cities around the world. I'm active in the the San Francisco Bay Area group. We hold meetings once a month, with one or two speakers. Many attendees are new to R.
  • Another online place to ask questions is Stack Overflow.
©

R в C++

Последнее время, по теме R на хабре появляются все новые посты: habrahabr.ru/post/161625/#habracut, habrahabr.ru/post/162583/. И мне захотелось обратить внимание на один важный момент. R – это не только язык программирования, но и огромная математическая библиотека, с уклоном в статистическую обработку данных. В данной статье я хотел бы рассказать, как использовать R в программах, написанных на с++.

В своем составе R имеет сишный интерфейс, однако в нем представлено далеко не все. Чтобы использовать возможности R на полную, существуют специальные пакеты: Rcpp и RInside. Пример, рассматриваемый в данном посте писался под Ubuntu 12.10, хотя, насколько мне известно все необходимое есть и для Windows.

Установка необходимых пакетов

Устанавливаем R и Rcpp: apt-get install r-base r-cran-rcpp2. Rcpp – библиотека для интеграции R в C++.
2. Запускаем R (в командной строке набираем: R) и устанавливаем дополнительные пакеты, из командной строки:
RInside – это враппер над Rcpp, который делает работу с Rcpp очень простой
install.packages(«RInside»), если не получилось скачиваем архив с cran.r-project.org/web/packages/RInside/index.html, затем опять в командной строке R: install.packages(file.choose(), repos=NULL), выбираем архив.
Fitdistrplus – пакет расширяющий набор математических функции R
install.packages(«fitdistrplus»), если не получилось скачиваем архив с cran.r-project.org/web/packages/fitdistrplus/index.html, затем опять в командной строке R: install.packages(file.choose(), repos=NULL), выбираем архив.



Теперь задача

Например, необходимо определить гипотезу распределения случайной величины.

Сначала рассмотрим как это выглядит в R:


library(fitdistrplus) #Загрузим пакет, который легко позволяет определять основные моменты распределения.
x = rnorm(1000, 10, 5) #Запишем в x 1000 значений с нормальным распределением, математическое ожидание – 10, ср. кв. отклонение - 5
plot(x) #Посмотрим график



Для определения гипотезы распределения необходимо знать параметры распределения случайной величины. Найдем параметры (для нормального распределения: мат ожидание и ср. кв. отклонение) и запишем в переменные mean и sd.

params = fitdist(x, "norm");
mean = params[[1]][[1]]
sd = params[[1]][[2]]


Теперь проверим гипотезу распределения на нормальный закон. Для этого будем использовать тест Колмогорова – Смирнова. При уровне значимости, альфа = 0.05 гипотеза должна быть отвергнута если альфа > p-value.

ks.test(x, "pnorm", mean, sd)
#out:
#One-sample Kolmogorov-Smirnov test
#data: x
#D = 0.0199, p-value = 0.8236


p-value = 0.8236 > alfa -> гипотеза устраивает
Теперь проведем тот же тест, но в качестве исходных данных подсунем случайную величину распределенную по равномерному закону.

y = runif(1000, 0, 20)
plot(y)



params = fitdist(y, "norm");
mean = params[[1]][[1]]
sd = params[[1]][[2]]
ks.test(y, "pnorm", mean, sd)
#out
#One-sample Kolmogorov-Smirnov test
#data: y
#D = 0.0659, p-value = 0.0003399



как видно p-value получился меньше alfa, следовательно гипотезу можно отвергнуть

Теперь попробуем повторить примерно тоже из c++.


Перед сборкой необходимо настроить пути на три пакета:
R, Rcpp, RInside (туда куда поставили):
Например R/include; Rcpp/include; RInside/include
R/lib; Rcpp/lib; RInside/lib

В этом примере мы создадим массив случайных чисел от 0 до 1000 и попробуем проверить гипотезу, что случайная величина распределена по нормальному закону.

Основная суть работы с R в C++ заключается в том, что мы заполняем строки на языке R и при помощи классов RInside и Rcpp выполняем их. 

#include <RInside.h> 

int main(int argc, char *argv[]) {
    std::string evalstr = "";  // строка для формирования кода на R
    RInside R(argc, argv);  //окружение
    Rcpp::NumericVector RndVec(1000);  // создаем массив чисел
    for(int i = 0; i < 1000; ++i)
        RndVec(i) = (float)(rand() % 100); // заполняем его
    R["RndVec"] = RndVec; // связываем с массивом в R
    SEXP ans; // результат
    // формируем строку для R:
    // пробуем получить параметры распределения, считая, что это нормальный закон
    evalstr = "library(fitdistrplus) \n \
    out <- fitdist(RndVec, \"norm\", \'mme\')[[1]][[1]]; print(out); out";
    // получили результат
    ans = R.parseEval(evalstr);
    // получили матожидание 
    Rcpp::NumericVector mean(ans);
    std::cout << "mean " << " is " << mean[0] << std::endl;
    evalstr = "out <- fitdist(RndVec, \"norm\", \'mme\')[[1]][[2]]; print(out); out";
    ans = R.parseEval(evalstr);
    // получили ско
    Rcpp::NumericVector sd(ans);
    std::cout << "sd " << " is " << sd[0] << std::endl;
    R["curMean"] = mean[0];
    R["curSd"] = sd[0];
    // выполнили тест
    evalstr = "out <- ks.test(RndVec, \"pnorm\", curMean, curSd)[[2]]; print(out); out";
    ans = R.parseEval(evalstr);
    Rcpp::NumericVector v1(ans);
    // посчитали p.value
    std::cout << "p.value " << " is " << v1[0] << std::endl;
    return 0;
}


Результат выполнения программы:

p.value is 0.000394703

Т.е. мы выбрали не верную гипотезу.

Заключение


Наверное код в данной статье не идеален, но цель была рассказать о возможности довольно просто использовать весь функционал R на c++, кроме того существуют библиотеки для подключения R к другим языкам, например java.

Ссылки


Вся информация доступна на вики en.wikipedia.org/wiki/R_(programming_language) + две статьи с хабра.
©

Installing R in Ubuntu

Universe

The current version of R available when a new version of Ubuntu is released is always available in the universe repository. To install R:

sudo apt-get install r-base

R package installation in ubuntu
install.packages("fitdistrplus")

©