Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The use of quotation marks when loading a package in R

Tags:

r

r-package

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?

like image 435
guyabel Avatar asked Apr 22 '16 19:04

guyabel


People also ask

What are quotation marks used for in R?

They can be used interchangeably but double quotes are preferred (and character constants are printed using double quotes), so single quotes are normally only used to delimit character constants containing double quotes. Backslash is used to start an escape sequence inside character constants.

What is the purpose of quotation marks in coding?

Straight single and double quotation marks are used in most programming languages to delimit strings or literal characters. In some languages (e. g. Pascal) only one type is allowed, in some (e.

How do you add quotation marks in R?

To add single quotes to strings in an R data frame column, we can use paste0 function. This will cover the strings with single quotes from both the sides but we can add them at the initial or only at the last position.

How do I remove quote marks from data in R?

Sometimes column values in an R data frame have single quote associated with them and to perform the analysis we need to remove that quote. Therefore, to remove single quote from string column, we can use gsub function by defining the single quote and replacing it with blank(not space) as shown in the below examples.


1 Answers

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

  • If you submit a paper to the Journal of Statistical Software they insist that package names are in quotes
  • Advanced R programming gives the downsides and also suggests against it.

The argument against

library(MASS)

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

pkg = "MASS"
library(pkg)

will do.

like image 51
csgillespie Avatar answered Sep 30 '22 14:09

csgillespie