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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With