16

Is there any reason to prefer the use of quotation marks when loading a package; e.g.

library("MASS")

over loading packages without putting the name in quotes;

library(MASS)

Looking back at some old code, I seem to switch between the two with no noticeable consequences. Is there a best practise recommendation to follow?

guyabel
  • 8,014
  • 6
  • 57
  • 86
  • 2
    [Recommended reading](http://adv-r.had.co.nz/Computing-on-the-language.html#nse-downsides) – RHertel Apr 22 '16 at 19:48
  • In addition, if you search the source code of `library()`, you can find this snippet: `if (!character.only) package <- as.character(substitute(package))`. So no matter if you use `library("MASS")` or `library(MASS)` because you didn't change the default argument `character.only = FALSE`, it would convert the package variable to a character type, i.e. they are not different. – Adam Birenbaum Apr 22 '16 at 20:28

1 Answers1

13

This is an example of non-standard evaluation. I'm not sure there is "best practice" regarding whether you should put packages in quotes. But

The argument against

library(MASS)

is that for new users, it's hard to guess what

pkg = "MASS"
library(pkg)

will do.

csgillespie
  • 59,189
  • 14
  • 150
  • 185