Various computing tips

[ Unix/Linux | Emacs | LaTeX | R | Other ]

Send an email to Karl Broman (kbroman at jhsph.edu) if you have suggestions for additions, subtractions, clarifications, corrections, or modifications.


Unix/linux

  1. xlsfonts lists all the available fonts
  2. A list of X windows colors is in the file /usr/X11R6/lib/X11/rgb.txt or (on athena) /usr/openwin/lib/rgb.txt
  3. scp is great for transferring files between machines. (e.g. scp myfile athena:somedir/)
  4. [linux] C-alt arrow switches between workspaces.
  5. [linux] convert for converting images between formats.
  6. Put the following alias in your .tcshrc in order to search all .c and .h files recursively, find instances of a given word in the file, and print those instances along with the file names. (For example, use fnd main)
      alias fnd 'find . -name "*.[ch]" -exec grep \~* {} \; -print'
  7. Differences between Windows, MacOS, and Unix in the character used to indicate line endings in text files are a constant annoyance. One uses a line feed, one uses a carriage return, and one uses both; I can never remember which. But the difference often causes problems. If you load a text file into emacs or vi, you can determine the current format. On enigma, use the commands dos2unix and unix2dos to convert files between formats. Use dos2unix -c Mac filename if the file is in MacOS format.


Emacs

  1. Ctrl-S for searching.
  2. Ctrl-x u for Ctrl-Shift-_ for undo.
  3. Esc-% (y/n/!) for replacement.
  4. Ctrl-number character or Esc-number character repeats that character.
  5. ! in directory listing mode executes a shell command on that file.
  6. Automatically turn on syntax highlighting and active region highlighting by adding the following to your .emacs file:
      (global-font-lock-mode t)
      (setq-default transient-mark-mode t)
  7. Use emacs -nw when using emacs remotely over a slow connection.
  8. Look at Karl's .emacs file for examples of macros (~kbroman/.emacs).
  9. Use Esc-x spell-word to check the spelling of the word on which you're currently sitting
  10. To create a macro to put in your .emacs file:


LaTeX

  1. See the local LaTeX documentation.
  2. Computer modern sans serif font: \renewcommand{\familydefault}{cmss}
  3. An easy way to revise margins: \usepackage{geometry} (e.g., use \geometry{margin=1in})
  4. natbib for bibliographies
  5. The colortbl package for creating color tables
  6. A macro for getting a different version of the symbol for the real numbers: \newcommand\R{{I\!\!R}}
  7. \usepackage{times} to use a times font that is generally rendered more nicely than computer modern.
  8. To get a PDF file from a LaTeX document:

    1. Sometimes ps2pdf gets the fonts mucked up. One way to avoid this:
        latex myfile.tex
        dvips -Ppdf -t letter -G0 myfile.dvi
        ps2pdf myfile.ps
    2. dvipdfm will also create a PDF file from a dvi file with the correct fonts. For example,
        latex myfile.tex
        dvipdfm -p letter myfile.dvi
      Specifying the "letter" papersize is important because the default may be a4.
    3. [linux] Sometimes when you use dvipdf, the pdf file looks awful in the reader but prints okay; dvipdfm (free to download) gets around this.
    4. The program ~ririzarr/bin/mydvipdf has all the right options to make high quality pdf from dvi. Use \usepackage{times} to make sure the fonts exist.
  9. If you use (encapsulated) PostScript figures (e.g. from R), ghostscript will occasionally automatically rotate your figure 90 degrees when you convert your document to PDF. The explanation is a little long but it is considered a "feature". You can disable this by doing:
    setenv GS_OPTIONS "-dAutoRotatePages=/None"
    at the shell (or the bash equivalent).
  10. Use texi2dvi --pdf to include png files in latex documents. (See the vignettes in Rafael's packages.)
  11. The following can be used to increasing the spacing in tables.
      \renewcommand{\arraystretch}{1.3}
      \renewcommand{\tabcolsep}{12pt}
  12. Books:


R

  1. Turn off those damned significance asterisks! Use options(show.signif.stars=FALSE), preferably in your .Rprofile (see more about that file below).
  2. expand.grid is really handy if you need to plot a 2D function using image.
  3. any and all are useful (e.g., any(is.na(mydata$age)))
  4. It's critical to get to know lapply, sapply, and tapply intimately.
  5. Lists are your friend.
  6. The file .Rprofile can be used to load up packages when starting R. For example, it might contain:
      options(defaultPackages = c(getOption("defaultPackages"), "foreign", "MASS"))
    You can put a .Rprofile file in your home directory and others in certain working directories. If one exists in a working directory, it's used in place of your main one; otherwise, the main one is used.
  7. help(plotmath) contains examples of mathematical symbols you can use in R. Here's a really complicated example:
      plot(rnorm(100),rnorm(100),xlab=expression(hat(mu)[0]), ylab=expression(alpha^beta),
           main=expression(paste("Plot of ", alpha^beta, " versus ", hat(mu)[0])))
  8. [Windows] R will interpret the standard emacs key-bindings. For example, if you have separate windows with emacs and R running, you might use Esc-w to copy within emacs, Alt-tab to switch to your R window, and then Ctrl-y to yank/paste into R.
  9. If you don't like reading scientific notation, you can set options("scipen") to some positive number to penalize scientific notation. For example, put options(scipen=4) in your .Rprofile
  10. stopifnot() is useful for self-documenting code.
  11. png is better than postscript for graphs with oodles of overlayed dots.
  12. Functions should return values rather than print stuff.
  13. If you create your own version of a summary() function, the function summary.myclass shouldn't print anything, but rather should return an object of class "summary.myclass". You should then make another function print.summary.myclass() which prints a summary of that.
  14. Use gc() to determine how much memory R is taking up. Use object.size() to detemine the amount of memory taken up by particular objects in your workspace. memory.profile() is useful sometimes to find out how much memory is being used by different types of objects.
  15. Use str() to get a compact display of the internal structure of a complex object.


Other

  1. To count the number of words in a PDF document: set the view option in Acrobat Reader to "continuous", copy the whole document and paste it into the text file, and then use wc -w to count the number of words.
  2. In R (and Fortran), matrices are stored by columns. (This is important to know when moving matrices between C, R, and Fortran.)
  3. When testing code, think about different cases that might break different parts of your code. (For example, with matrix multiplication, consider really tall by really wide vs. really wide by really tall.)
  4. Mozilla Firefox (previously called Firebird) is a really good multi-platform web browser with tabbed browsing (who could live with out it?) and mouse gestures (who over 30 has any idea what this is?).
  5. knoppix is a bootable linux distribution that you can use if you want to try out linux without overwriting your windows installation.


[ Unix/Linux | Emacs | LaTeX | R | Other ]

Last modified: Wed Apr 15 23:00:36 2009