Monday, 25 April 2016

A paragraph I am thinking about


Explorers Elisha Kane and Isaac Hayes wintered with the Polar Inuit in 1853 and 1861, respectively, and reported that the Polar Inuit lacked kayaks, leisters, and bows and arrows and that their snow houses did not have the long heat-saving entryways that were seen among other Inuit populations. They could not hunt caribou, could only hunt seals during part of the year, and were unable to harvest arctic char efficiently, although char were plentiful in local streams (28). Apparently the population was struck by an epidemic in the 1820s that carried away the older, knowledgeable members of the group, and according to custom, their possessions had to be buried with them (29). The Polar Inuit lived without these tools until about 1862, when they were visited by a group of Inuit who migrated to Greenland from Baffin Island (28, 29). There is every reason to believe that these tools would have been useful between 1820 and 1862. The Polar Inuit population declined during this period, and the tools were immediately adopted once they were reintroduced. After their introduction, population size increased. It is also telling that the kayaks used by the Polar Inuit around the turn of the century closely resemble the large, beamy kayaks used by Baffin Island Inuit and not the small sleek kayaks of the West Greenland Inuit. Over the next half century the Polar Inuit kayak design converged back to the West Greenland
design (30). If this inference is correct it means that for 40 years (nearly two generations) the Polar Inuit could have benefitted from the lost knowledge. Moreover, they collectively remembered kayaks, leisters, and bows and arrows, but did not know how to make them and could not recreate that knowledge.

Boyd and Richerson PNAS 2011. Ungated copy of original article.




Thursday, 21 April 2016

R tip: run commands without brackets

Using R, I often want to type quick commands in. But R commands always have brackets. Typing brackets (e.g. ls()) is a big hassle. I find myself missing the unix command line where you can just type ls.

So, here’s a quick hack to do just that. Put the following in your .Rprofile file in your home directory.


print.command <- function (x) {
  default.args <- attr(x, "default.args")
  if (! length(default.args)) default.args <- list()
  res <- do.call(x, default.args, envir=parent.frame(2))
  if (attr(x, "print_result")) print(res)
  invisible(NULL)
}

make_command <- function(x, ..., print = TRUE) {
  class(x) <- c("command", class(x))
  attr(x, "default.args") <- list(...)
  attr(x, "print_result") <- print
  x
}


Now, just add the following for any command that you’d like to type without brackets. For example, for ls:

ls <- make_command(ls)

From now on, typing the command will run it.

If you want to include default arguments, add them as arguments to make_command, and if you don’t want to print the result, add the argument print = false. So, for a quick way to turn debugging on, I use:

oer <- make_command(options, error = recover, print = FALSE)

Typing oer at the command line now runs options(error = recover). All without undue stress on my little finger and the Shift key.