1 # Community Data Science Collective R Utilities
3 # Copyright (c) 2010-2016 Benjamin Mako Hill and Aaron Shaw
4 # mako@atdot.cc, aaronshaw@northwestern.edu
6 # load a file if a variable is missing
7 load.if.missing <- function (var.name, file.name) {
8 if (!exists(var.name)) {
9 load(file.name, parent.frame())
11 # check to see if we're dealing with a data.table because, if we
12 # are, we need to do some nasty back and forth
13 if (class(eval(as.name(var.name)))[1] == "data.table") {
15 # gnarly function that loads resorts things within the parent
16 # frame to get around the bug in data.table
18 data.table(as.data.frame(eval(as.name(var.name))),
19 key=attr(eval(as.name(var.name)), "sorted")),