10.4.09

R Statistical software

R is a statistical computing scripting language not dissimilar to Matlab or Python.
R is a GNU project implementation of the S programming language with lexical scoping semantics inspired by Scheme. The R language has become a de facto standard among statisticians for the development of statistical software.

Resources:

3.4.09

Mother May I?

Unix uses the concept of permissions and ownership to determine who can access a file or directory. Each file or folder is considered to be owned by a user and a group (typically group to which the user belongs). There are a set of permissions associated with each file or folder that determines what actions on that file or folder are allowed for a particular user. There are three types of permissions:
  • r - read, allows you to read the contents of a file
  • w - write, allows you to write to a file or delete it
  • x - execute, allows you to run a file as a script, or cd to a directory.
and three groups to set permissions on:
  • User or Owner is the person who created the file
  • Group is the group that the owner belongs to
  • Other is everyone else in the world.
You can see the ownership and permissions for a file or folder by using the ls command with the -l option. For example, if readme is a file in the current folder:
ls -l readme
might give the results:
-rw-r--r-- 1 bob staff 0 Jun 17 23:30 readme

This shows that the file readme is owned by user bob and group staff. The permissions are shown by the sequence of ten characters at the start of that line: -rw-r--r--. The first character is a - for a file. Alternatively if it were a d it would indicate a directory. The next three characters (rw-) indicate the permissions for the owner of the file (bob). The next three characters (r--) indicate the permissions for a user who is not the owner of the file, but who is in the group (staff) that owns the file. The last three characters (r--) indicate the permissions for everyone else.

You can remove a read-only file from a directory only if you have write permission for that folder (-rw-r--r--). Typically directories must have execute permission if you want people to have read permission.


Changing permissions

To change the permissions on a file or folder, use the chmod command.
For details, see man chmod. The easiest way to change permissions is to use the symbolic modes where the permission changes are specified by add +, remove -, or set = permissions. Use u to indicate that the change applies to the user permissions, g to indicate that it applies to the group permissions, and o for anyone else.

To change the permissions on the file readme to allow the world to have write permission:

chmod o+w readme

If the file isn't owned by the user, preface the command with sudo and supply a superuser password:
sudo chmod g+w readme

To add executable permission to the file (e.g. because it is a script) for the owner of the file and for users in the group that owns the file use:
chmod ug+x readme

To remove the read and write permissions for the group and the world:
chmod go-rw readme

Use the the set = operation to set the permissions to an exact configuration - without regard to what the permissions are currently. To set the file to be readable and writable by the owner, but only readable by group and "other":
chmod u=rw,go=r readme

Things work similarly for directory permissions. Often you want to change the permissions of a directory and all its contents. Do this with the -R option to chmod.

To change a directory and all its contents to be writable by the owner and group use:
chmod -R ug+w Folder

Likewise, the flag X (uppercase) can be combined with the -R option to ensure that a folder and all of its sub-folders have execute permission, but not the files. Typically execute permission is not desirable for files unless they are applications or scripts.
chmod -R ugo+X Folder


2.4.09

Fundamental Unix Commands

Overview of the Apple OS X BSD UNIX implementation

Opening a terminal

To access the UNIX subsystems in OS X you need to open the terminal application. The terminal is located in the Utilities folder under applications.

Navigating in the terminal
  • The horizontal arrow ←→ keys move the cursor left and right
  • The vertical arrow ↑↓ keys page through the command history.
  • Use the mouse to select text (by highlighting) and ⌘c and ⌘v to cut and paste text
  • Delete deletes text behind the cursor the ⌦ key deletes text after the cursor.
Nomenclature


There are numerous concise ways to specify directory information.
  • . indicates your current directory
  • .. indicates the directory right above you on the tree, or parent to the current directory.
  • ~ indicates the users own home directory
  • ~smith indicates the user Smith's own home directory
  • / the root directory, or top of the tree.

Basic Unix Commands

CP: cp copies a file from a source name to a target name.

cp [modifiers] /<filename> /<filename>


Some common modifiers for copy are:
-r for recursive (used to copy whole directories)
-f force (don’t ask me if I want to do it just do it)
-P preserve permissions

For example
cp /usr/share/tcsh/examples/login ~/login

copies the default login file for the tcsh shell located in the /usr/share/tcsh/examples to your home directory. See the article on shells for more information on the login file.

MV: mv moves a file from one directory to another, or from one name to another, or a combination of both. It often confuses new users that renaming in Unix is the same as moving.

mv [modifiers] /<filename> /<file>


Some common modifiers for move are:
-r for recursive (used to copy whole directories)
-f force (don’t ask me if I want to do it just do it)
-P preserve permissions

For example
mv login .login

just renames the file login to .login.

RM: rm removes a file or with the -r modifier, a directory.

rm [modifiers] /<filename/directory>


Some common modifiers for move are:
-r for recursive (used to delete whole directories)
-f suppresses confirmation prompts asking if you really want to delete read-only files.

For example
rm -rf /usr/local/bin

removes the directory bin, in /usr/local, if you have permission to do so. Note this is NOT something that is a good idea to try.

CD: cd changes the current working directory.
cd

PWD: pwd displays the current working directory.

MKDIR: mkdir creates a new directory
. Some common modifiers for mkdir are:
-p used to create a whole hierarchy of folders in one step.


For example
mkdir -p work/version1/code

creates the directory code inside of the directory version1, which is inside a directory work. And work is created in the current working directory.

LS: ls displays the contents of a specified directory. By default it displays the current directory.
ls [modifiers]
or
ls [modifiers] /<filename/directory>

Some common modifiers for ls are:
-l provides a long listing of the file information.
-lt provides a long listing but now sorted in chronological order
-a lists all files, including hidden dot files.
-d lists the directory itself (the default behavior lists the contents of the directory instead).

For example
ls -t /usr/share/tcsh/examples

lists the contents of the directory /usr/share/tcsh/examples in the chronological order in which they were created.

Last of all, is the command that helps you find out more about any command. This is the man command.

MAN: man accesses the built in manual pages. For example to find all the modifier options for ls, type:
man ls

to find the name of a command which does something specific use the -k modifier.

man -k password

lists all the commands which deal with passwords. Alternatively use the command apropos which searches through the header lines of the man pages for whatever keyword you supply, and lists the man pages containing it. For example,

apropos copy

produces a list of all the man pages that contain copy in their header lines.

This is just the begining, there is more Unix to come, but this will get you started.