The @#$%&!ing Coconut

After having my laptop "fixed" by the Coconut (which has taken since Tuesday January 17–currently March 3rd) and subsequently having to re-install many of my applications and all of their preferences at least twice in that span, I am writing this post to document some of the steps I have taken to make my system workable again.

Library Folder
First off, I was updated to OS 10.7 (Lion) from a workable Snow Leopard. Many of the preferences and extras that make life workable for computing wizards is stored in the users ~/Library folder on a Mac. Apple has decided to remove that folder from sight because most users are not wizards....or maybe because many teenagers don't know what a library is anymore. Regardless, this is unacceptable. The folder is actually still there, but it is just not visible. This can be changed by opening Terminal (/Applications/Utilities/Terminal) and then typing
chflags nohidden ~/Library
Wallah! The Library folder is now visible.

I also needed the one-click run for TeXShop. To do this I copied the following into a file called Sweave.engine which I then put into the ~/Library/TeXShop/Engines folder.


export PATH=$PATH:/usr/texbin:/usr/local/bin
R CMD Sweave "$1"
pdflatex "${1%.*}"
The PATH= gives the location of your TeX distribution. This puts the Sweave option under the typesetting menu (see below), and runs both Sweave and PDFtex when the Typeset button is pressed.
If it will not run, the permissions to execute the file might also need to be changed. In Terminal, type
chmod +x ~/Library/TeXShop/Engines/Sweave.engine
This allows the file to be executed.

Sweave and TexShop
As of R v. 2.8, the default manner in which it linked to the Sweave files. This is easily fixed. Open Terminal,
mkdir -p ~/Library/texmf/tex/latex 
cd ~/Library/texmf/tex/latex 
ln -s /Library/Frameworks/R.framework/Resources/share/texmf Sweave
Line 1 creates a texmf, tex and latex folder (each subsequent folder embedded the others in the user's Library folder. Line 2 will change directory so that you are in the latex folder. The last line, will create a link from your user's tex directory to the Sweave files that R uses. Now it is possible to just use the following line in TexShop:

Turn Off File Locking
The Lion OS introduced automatic file locking for any file that hasn’t been edited recently. You will notice this when you try and open an older file and make changes to it, a dialog box asks to duplicate the file or to manually unlock it. This is problematic (and annoying) for things like updating R packages. The solution:
  • Open System Preferences > Time Machine
  • Click the Options button
  • Uncheck the Lock Documents box
Turn Off File Vault
File Vault is Lion's hard disk encryption system. Worthwhile if you are a main character on the TV show Homeland, otherwise, not so much. To adios this,

  • Open System Preferences > Security and Privacy
  • Click the Turn Off File Vault button
This may take awhile depending on how much data you have. It took my system roughly 6 hours.

A syntax editor is a must for all data scientists. I use TextWrangler, the free version of BBEdit. To make Text Wrangler more compatible with R, there are two things that you need to do which are essential. (1) Add functionality to run syntax directly from TextWrangler, and (2) change the color theme. For the former,
  • Download the SendSelToR.txt file from macsi
  • Change the file suffix from .txt to .scpt (applescript)
  • Move the file to TextWrangler's Scripts folder (~/Library/Application Support/TextWrangler/Scripts)
  • Open Text Wrangler and from the Window menu select Palettes > Scripts
  • You should see the SendSelToR script. If so, hit the Set Key... button and type in a key command that you will then use to send the syntax to R. For example, ⌘-return is a common keystroke to run syntax.
To change the color theme,

  • Download the syntax highlighting file (R.plist) from macsi
  • Move this file into Text Wrangler's Language Modules folder (~/Library/Application Support/TextWrangler/Language Modules/)
  • Restart Text Wrangler
  • From the TextWrangler menu select Preferences > Languages
  • Add a new suffix mapping (e.g., .r to R language)

This gets things ready, next,

  • Download BBColors from Daring Fireball
  • Open the zip file and move bbcolors to some location in your shell’s PATH (a typical location would be /usr/local/bin/ or /usr/bin/)
  • Download a color scheme file (.bbcolor files) that you like. Daring Fireball provides a couple. I personally like Ethan Schoonover's Solarized (Dark) theme which is available through GitHub. That being said, I use Ghetto Cooler's Gentle Honey because it is easier for students to see when I project scripts in class.
  • Go to ~/Library/Application Support/
  • Create a new folder called BBColors
  • Move any .bbcolor files into this newly created folder
  • Open Terminal and type
bbcolors -load "Gentle Honey" -tw
where Solarized Dark is the name associated with the .bbcolor file. The -tw will associate this with TextWrangler rather than BBEdit.

Transfer Settings
Importing over the old settings or preferences when you change computers is very time saving, although you may just want to start from scratch. The following is what I ported over

  • Stickies: The Stickies database is in ~/Library/StickiesDatabase. Copy and paste this into your new Stickies database.
  • iCal: The iCal data is stored in ~/Library/Calendar
  • Taco: The preferences data (syntax coloring, etc.) is stored in ~/Library/Preferences
  • Fonts: These are stored in ~/Library/Fonts
I used Dropbox to transfer these files over to my computer.

I also wanted to change the color theme for Terminal. I personally like Ethan Schoonover's Solarized (Dark) theme.

  • Go to Tomislav Filipčić's GitHub and click on the zip link to download the Solarized Light and Solarized Dark themes for the Terminal App.
  • After downloading the zip file, double click each theme in turn. This will add them to the preferences pane in Terminal.
  • Open Terminal and select Terminal > Preferences
  • Click the Settings pane
  • Choose a theme and click the Default button below the list of themes.
  • Re-open Terminal

Hidden Files
The easiest way to see hidden file is through Terminal. Open Terminal and type the following
defaults write com.apple.Finder AppleShowAllFiles TRUE
killall Finder
The first line will rewrite the Finder's preference file to show all files (including the hidden ones). The second line kills the Finder, causing it to reboot so that the preferences will take effect. When you are done messing with the hidden files you can hide them again by setting the last flag in line 1 to FALSE.

General Lion Slowness
Lion saves any file changes to your local drive so you can use Time Machine even if your external drive isn't connected. While they claim it doesn't slow things down, it might very well, especially when working on a large file. To disable local backups, open Terminal and type the following:
sudo tmutil disablelocal

No comments: