Posts Tagged ‘productivity’

Error notifications from R

4 Sep 2014

I’m enthusiastic about having R notify me when my script is done.

But among my early uses of this, my script threw an error, and I never got a text or pushbullet about that. And really, I’m even more interested in being notified about such errors than anything else.

It’s relatively easy to get notified of errors. At the top of your script, include code like options(error = function() { } )

Fill in the function with your notification code. If there’s an error, the error message will be printed and then that function will be called. (And then the script will halt.)

You can use geterrmessage() to grab the error message to include in your notification.

For example, if you want to use RPushbullet for the notification, you could put, at the top of your script, something like this:

options(error = function() { 
                    library(RPushbullet)
                    pbPost("note", "Error", geterrmessage())
                })

Then if the script gives an error, you’ll get a note with title “Error” and with the error message as the body of the note.

Update: I knew I’d heard about this sort of thing somewhere, but I couldn’t remember where. Duh; Rasmus mentioned it on twitter just a couple of days ago! Fortunately, he reminded me of that in the comments below.

Another update: Ian Kyle pointed out in the comments that the above function, if used in a script run with R CMD BATCH, won’t actually halt the script. The simplest solution is to add stop(geterrmessage()), like this:

options(error = function() { 
                    library(RPushbullet)
                    pbPost("note", "Error", geterrmessage())
                    if(!interactive()) stop(geterrmessage())
                })

Notifications from R

3 Sep 2014

You just sent a long R job running. How to know when it’s done? Have it notify you by beeping, sending you a text, or sending you a notification via pushbullet.

(more…)

Emacs key bindings in MS Word

12 Feb 2014

Collaboration on grant proposals has forced me to spend a lot of time writing in MS Word lately. I find my self typing emacs key strokes and then getting annoyed when I have to move my hand over to the arrow keys. (It’s maybe not as bad as typing Markdown marks within a LaTeX document, which I’ve also been doing.)

A google search on the title of this post got me to this post. I should have looked before.

Following that suggestion, I was able to get these:

C-b – CharLeft
C-f – CharRight
C-e – EndOfLine
C-p – LineUp
C-n – LineDown
C-a – StartOfLine
C-v – PageDown

I can’t figure out how to have M-v for PageUp, though, because M-v seems permanently stuck to “√”.

The procedure, in MS Word 2011 for Mac, is:

  1. Tools → Customize Keyboard
  2. Select “All Commands” under “Categories:”
  3. Select the command (e.g., RightChar) under “Commands:”
  4. Press the keyboard shortcut in the “Press new keyboard shortcut” box
  5. Click the Assign button
  6. Repeat for the other commands you want
  7. Click OK

I needed two more, C-d and C-k; it took me a while to figure out how to do it, as there didn’t seem to be any built-in commands. But you can just record a macro. I created these:

C-d – [DeleteCharacter] (as a macro)
C-k – [KillLine] (as a macro)

Here’s the procedure, in MS Word 2011 for Mac.

  1. Tools → Macros → Record Macro
  2. Give it a name with no spaces
  3. Click the keyboard button to assign a keystroke to it
  4. Select OK
  5. Type the set of key strokes
  6. Tools → Macros → Stop Recording

Womacs is a really extensive set of Visual Basic macros that looks really useful, but I was getting Visual Basic errors and didn’t want to spend any more time on it; grants to write…

What should I do badly?

23 May 2012

One of the more painful things to learn as a faculty member is to accept that you will do some things badly. There are too many things to do, so you can’t do them all well. What should you do badly?

As an undergraduate, the scope of work is reasonably precisely defined, and problem sets have relatively simple solutions. I finished things on time or even early, and I seldom felt guilty for not studying.

In the first year of graduate school, problem sets are much harder, but they still all have solutions. That there must be a short solution to every problem on an exam is generally the most important thing to recognize in attempting to solve them.

Later in graduate school, identifying a solvable problem becomes part of the research effort, but you can focus all of your effort on that work and so do everything well. For me, there was little need for time management, since I had loads of time.

Even as a postdoc, when I’d started to do many more things at once, I still had few responsibilities aside from my own work, and so I could do everything well. And basically what you need to get done is just defined as what you actually get done.

Faculty life is quite a bit different. I’m making real commitments to people. And then there’s teaching, and reviews of papers and grants, and committees, and letters of recommendation or evaluation. My personal research efforts often are pushed aside in favor of rush-rush collaborative work. Or I’ll spend weeks doing little but read and comment on others’ work.

There’s just too much to do and not enough time to do it as well as you’d like.

So, what should I do badly?

Well, definitely not my own research papers; those will outlast me. Maybe some day someone will read them. Similarly, not seminars I give, as through such research talks, I may gain a reader. I suppose family, health, and sleep should be mentioned here. And biking.

So:

  • Committee work. If someone says, “I enjoyed reading the report you wrote”, you’ve clearly been focusing on the wrong things.
  • Reviews of papers. Sure, I want to help out the authors, but I can’t be doing their research for them.
  • Teaching. If you try to do your best, you’ll do nothing else. The students may notice the difference between just dusting off last year’s notes and actually preparing (and fixing past mistakes), but will they really learn much more in the latter case? To learn, they must struggle a bit, e.g., through the errors in my notes. Is that just a rationalization?
  • Reviews of grants. Someone’s livelihood is at stake, but does it really matter if the text of my review is awkwardly phrased?
  • My own grant. Some of my colleagues will start writing a grant months in advance. I say: if you start months in advance, then you’re going to spend months on the thing! You should start as late as possible. A perfect score on a grant is an indication that you spent too much time on it. The best grant score is the worst possible that still gets funded.

As I said, it’s painful to do things that you know are crap (i.e., could be much better). It’s hard to accept one’s limitations.

Meetings vs work

28 Sep 2011

Rafael Irizarry wrote about how meetings at work get in the way of actual work.

I agree with his central point, that it can take some time to get back working on a project (whether data analysis, programming, or writing), and so blocks of less than a couple of hours can be inefficient. Meetings that break up a work day can really erode one’s productivity: academics often spend too much time meeting and not enough actually working, and three hour-long meetings spaced evenly throughout the day can mean that you don’t get anything real done in the other five hours.

(more…)