1. Background
  2. Text editor from the terminal
  3. Screen
  4. R in command line

Background

Back in 2010 and 2011, I experienced some of the worst earthquakes in New Zealand. It was devastating, Christchurch cathedral was destroyed during this disaster. The city centre was ruined. Our favourite pubs were closed for months! Our university was badly damaged, we had to study in tents, and work remotely because office was closed.

Ten years later, the bad luck strike again — the coronavirus outbreak in the UK. People are recommanded to work from home and stay safe. Here I dig up some notes to share, that some tools you may also find handy when working remotely with bad internet and command line interface becomes your only option.

Text editor from the terminal

First choose your favorite text editor: Emacs, vim or nano. Depends on what is used for, some editors are more preferred than the others. Most of the editors support syntax highlighting, e.g. vim; some of editors support brackets matching, or auto-completion; In the rest of this help file. I will be using Vim

There are many many websites where you can find help or tutorials for vim. The most common commands are

Command Usage
:q! Quit vim without save
:wq Save the current file, and exit
:w Save the current file
i Insert content
dd Delete current line
x Delete character to the right (equivlent to the “delete” key)
X Delete character to the left (equivlent to the “backspace” key)
/ blah Search “blah” in the current file
n Search for the next “blah”

Screen

If you want to run a job for several days, and you don’t want to leave the machine logged on. You can use Screen to run those jobs. At the current directory start screen with session name screen example

szh41@ubuntu:~/phd_diary/presentations/2010$ screen -S screen_example

Now you are inside the screen. Let’s run the screen shell script eg.sh file, which constantly prints out integer 1 to 100 on the screen.

#!/bin/bash
# screen_shell_script_eg.sh
I=1
for ((;I<=100;));  do
  if [ ${I} -eq 100 ]; then
      echo ${I}
      let I=1
    else
      echo ${I}
      let I++
  fi
done
szh41@ubuntu:~/phd_diary/presentations/2010$ ./screen_shell_script_eg.sh

Now you can start another window session by pressing “Ctrl+a, c”; press “Ctrl+a, shift+” ”, you can see the current running window sessions, by clicking the up or down arrow on the key board, you can select the running window;

Let’s detach the current running window by pressing “Ctrl+a, d”.

Let’s re-attach the screen.

szh41@ubuntu:~/phd_diary/presentations/2010$ screen -d -r screen_example

By doing so, you will see the previous session keeps running on the screen. We can use “Ctrl+c” to terminate such session, and use exit to terminate the screen session.

R in command line

Install your own R library at your own H drive. In R, use command install.packages(). Here I will demonstrate a example by installing package ZIGP on my own H drive. First, create a directory at my home directory

math/szh41> mkdir Rilbs

then, download the package to my Rlibs directory. Open R,

math/szh41> R

set the /Rlibs as one of my library Paths, and then install ZIGP in /Rlibs,

>.libPaths("~/Rlibs")
> .libPaths()
[1] "/users/math/szh41/Rlibs"
[2] "/usr/local/lib64/R-2.10.1/lib64/R/library"
>install.packages("~/Rlibs/ZIGP_3.8.tar.gz",lib="~/Rlibs")

Done! Library ZIGP is installed at the directory /Rlibs Now, let’s try and remove ZIGP, and recover the original library Paths.

>remove.packages("ZIGP",lib="~/Rlibs")
> .libPaths()
[1] "/users/math/szh41/Rlibs"
[2] "/usr/local/lib64/R-2.10.1/lib64/R/library"
> .libPaths(.libPaths()[2])
> .libPaths()
[1] "/usr/local/lib64/R-2.10.1/lib64/R/library"