R & RStudio - FAQ

After loading a new package, R tells me that a certain object is masked from another package. What does this mean?

Some objects are included in several packages. For example, the function alpha() is included in both ‘ggplot2’ and ‘psych’. The functions are not the same though. Loading ‘psych’ after loading ‘ggplot’ will give you the warning that alpha is masked from the ggplot2 package. In this case, if you are using the function alpha(), you will use the function from the psych package (as the one from the ggplot2 package is masked). Use `ggplot2::alpha` to still use the alpha function from the `ggplot2` package.

When using a command I get the message Error : could not find function:

Not all functions you need to use are always available. Many functions are part of packages. That means you need to first install and load the package before the function can be used. For example, the mutate() function is part of the tidyverse. Therefore, if the function mutate can’t be found, you need to load the tidyverse package with library(tidyverse). You can find which library a function belongs to in the function list of the relevant chapter, or by looking up the function on rdocumentation.org.

When trying to install a package I get the message that I need to install `Rtools`. How do I do that?

R-Tools is a program that is required to program and make packages yourself. Since you will not be doing that, you should not need R-Tools for any of the things you will be doing. However, sometimes RStudio still gives the message that R-Tools is required when installing a package, even when the installation of the package is going successfully. Therefore, when you try to install a package, your console might look something like this (I will install the library “tidyverse” in this example, but it will look similar with other libraries):

This may look like the installation failed and that you need to install Rtools, however, at the end it says that in fact the installation was successful. Usually, the package is successfully installed, despite the message saying that you need to install Rtools. You can test if the package is in fact installed properly, by calling:

Change “tidyverse” here of course in the name of the library you need. If you still keep having problems, you can try to install Rtools anyway (even though you probably don’t need it). You can download Rtools for Windows from here: https://cran.uni-muenster.de/bin/windows/Rtools/.

When loading the package I get the message Error: there is no package called ‘…’:

There are three reasons why R may display this error:

1)    There is a typing error in the name of the library when you’re trying to load it using library() function. Remember R is case sensitive.

2)    You have not yet installed the package. Make sure to run install.packages("___") with the name of the library before you try to load it with library() command.

3)    The package you’re trying to load is dependent on other smaller packages that cannot be loaded properly. Normally, when you install a package, the packages that it needs (dependencies) automatically get installed with it, but sometimes that’s not the case. We want to then specify to R that you want the dependencies to be installed with the main package by adding the argument `dependencies = TRUE`:

When you now load the tidyverse package using library(tidyverse) command the error should be gone.

When loading a package I get the message Error: Package ‘…’ is already loaded but version ‘…’ is required:

If R displays this error, it means that the package you are trying to load (or smaller packages that its dependent on) needs to be updated to the newest version in order to function properly.

1)    Make sure that you restart your R session for example by closing and opening R Studio again.

2)  Before you try to load any libraries we want to update those that give us errors. So if by loading tidyverse we get following message: Namespace ‘cli’ 2.3.0 is already loaded, but >= 2.4.0 is required, we want to first delete the package cli and then install it again:

3)    Try to load the tidyverse package now. If similar error appears with different package name make sure to adjust and re-do step 2. If the error still persist with the same library you may want to remove tidyverse package and re-install it: