One thing that intimidates new R and RStudio users is how it reports errors, warnings, and messages. R reports errors, warnings, and messages in a glaring red font, which makes it seem like it is scolding you. However, seeing red text in the console is not always bad.
R will show red text in the console pane in three different situations:
Error in ggplot(...) : could not find function "ggplot"
, it means that the ggplot()
function is not accessible because the package that contains the function (ggplot2
) was not loaded with library(ggplot2)
. Thus you cannot use the ggplot()
function without the ggplot2
package being loaded first.Warning: Removed 2 rows containing missing values (geom_point)
. R will still produce the scatterplot with all the remaining non-missing values, but it is warning you that two of the points aren’t there.read_csv()
function as you’ll see in Chapter 4. These are helpful diagnostic messages and they don’t stop your code from working. Additionally, you’ll see these messages when you install packages too using install.packages()
as discussed in Subsection 1.3.1.Remember, when you see red text in the console, don’t panic. It doesn’t necessarily mean anything is wrong. Rather:
If the text starts with “Error”, figure out what’s causing it. Think of errors as a red traffic light: something is wrong!
If the text starts with “Warning”, figure out if it’s something to worry about. For instance, if you get a warning about missing values in a scatterplot and you know there are missing values, you’re fine. If that’s surprising, look at your data and see what’s missing. Think of warnings as a yellow traffic light: everything is working fine, but watch out/pay attention.
Otherwise, the text is just a message. Read it, wave back at R, and thank it for talking to you. Think of messages as a green traffic light: everything is working fine and keep on going!
Attribution: This section is adapted from ModernDive by Chester Ismay and Albert Y. Kim
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.