Troubleshooting R

Author

Wei Miao

Published

September 29, 2022

In this page, I summarize the common issues running R and the troubleshooting tips. If you run into any R issues, please refer to this page as the first step for any solution.

1 ‘could not find function’ Error

This error arises when (1) an R package is not loaded properly, or (2) due to misspelling of the functions.

As you can see in the screenshot below, when we run the code, we get a could not find function “praise” error in the console. This is because we have not loaded the package “praise” to which the praise() function belongs.

We need to first load the package that contains the function we want to run using library() as shown below:

library(praise)

and then use the function praise() to run it error-free.

praise()
[1] "You are fantabulous!"

Meanwhile, if we misspell the praise() function, for instance, to prais(), this will also throw up a could not find function “prais” error.

prais()
Error in prais(): could not find function "prais"

2 ‘object not found’ error

This error occurs when the particular object used in the code is not yet created or existing in the R environment.

In the example below we are trying to compute x plus 4. As you can see, we get an ‘object ’x’ not found’ error as the “x” object is not yet created and missing in our R environment.

x+4
Error in eval(expr, envir, enclos): object 'x' not found

Solution

Based on the missing object, go back to your previous codes and check why the object is missing. Did you forget to create it? Did you accidentally delete it?

4 Prompt Window: “R packages not up-to-date”

Since the R packages are being updated every day (just like our mobile apps, there could be bugs so that the developers have to update R packages to fix those bugs), sometimes, though we may have installed some packages, they are too old to run the functions. And you may see this prompted message:

It means, the aforementioned packages, base64enc, digest, etc. are outdated and must be updated to function.

Solution

Click Yes and RStudio will update all the packages for you.

5 Latex not found when kniting the .rmd/.qmd file.

If this is your first time to knit the PDF document, you may see an error message as below:

The error message has usually told us everything on how to troubleshoot (that’s what an error message is for!).

In this screenshot, if you read along, you will find the cause of problem:

[…] LaTex failed to compile,

because

[…] No LaTeX installation detected (LaTeX is required to create PDF output).

and the solution is also consideratebly given in this error message:

[…] You should install a LaTeX distribution for your platform: https://www.latex-project.org/get/

If you are not sure, you may install TinyTeX in R: tinytex::install_tinytex()

So this error message tells us the solution:

Solution

Alternative solution 1:

Run the following command in Console

tinytex::install_tinytex()

in order to install tinytex, a simplied version of LaTex, on your laptop.

Alternative solution 2:

Install LaTex on your computer following the R installation guide

If you run the command in R Console, you will see that Latex is being installed

After this progress bar finishes, you will be able to knit the PDF document!

6 Error: Connection Not Found

Connection Not Found error is usually caused by RStudio being unable to locate your files on your hard disk.

If you don’t know how to find the path names for a file on your computer, please refer to

  • this link for Windows
  • this link for Mac

7 More Questions

Please leave a screenshot of error message in the MSTeams channel named “R QnA”. I will keep updating this webpage as more questions come in.