Skip to Main Content

Datalab: Troubleshooting in R

Installation problems

I receive the error message when i try to install a package WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

Answer: 
The problem might be that you have installed RStudio prior to R.

  1. Close RStudio
  2. Uninstall everything related to R, i.e. R, RStudio and RTools.
  3. Reinstall R and RStudio in the correct order and try again, see installation instructions
  4. Open RStudio and try to install the package again
  5. If you still receive the same error message close RStudio. Download and install RTools manually from here.
  6. Open RStudio and try to install the package again.

I'm having trouble installing the stats package and get the error Warning in install.packages :       package ‘stats’ is in use and will not be installed

Answer:
stats is part of base R, it can't be installed using install.packages(). Only contributed packages can be installed that way. The way to update stats is to update the R installation

Set Working Directory

I can't import my dataset and receive the error message
Error: `path` does not exist: ‘CRSP_index_monthly.xlsx’

Answer:
The file you are trying to import is not in your working directory. Change the working directory to the correct path

  1. Go to Session
  2. Choose Set Working Directory - > Choose Working Directory
  3. Browse to the correct path and try to run the command again

The console should now show your working directory

You should also see the correct path and file in Files section

Problems with various packages

ggplot

I get the message Error in plot.new() : figure margins too large when I have made a plot.

Answer:
Try to fix the error by increasing the size of the plot panel

 


MASS

I get the message Error in unloadNamespace(package) : namespace ‘MASS’ is imported by ‘TH.data’ so cannot be unloaded when using the MASS package

Answer:
Try to close RStudio and open it again. Run the code again and it should work.

 

tinytex and problems with compiling PDF's

There are various issues with compiling PDF's with tinytex but here are some suggestions on how to make it work.

First of all you need to check that the code runs without any errors. If there are errors in the code then the compiling will fail. Try a script with little code to see if tinytex is actually working.

 

Check that everything is updated

Help -> Check for updates (Restart RStudio after the update)


Update all packages in RStudio with the following command

update.packages(ask = FALSE, checkBuilt = TRUE)
Remember to restart RStudio after the update)

Try to compile your script to see if it works. If it doesn't woek go to the debugging section.

 

Now to the debugging of tinytex

Check if tinytex is actually installed

tinytex::is_tinytex()

Install/reinstall tinytex with the following command, be aware that this differs from the normal package installations

tinytex::install_tinytex()
Restart RStudio after the installation and try to compile to PDF. Try to to compile to HTML if the PDF fails. If the HTML compiles 
correctly we know that tinytex is working and have isolated the problem to PDF.

If compiling PDF and/or HTML fails you could try to uninstall tinytex and reinstall

Uninstall tinytex
tinytex::uninstall_tinytex(force = TRUE)

Reinstall tinytex
tinytex::install_tinytex()

 

Problem with administration rights

Some may encounter issues with trying to run tinytex from a path where you don't have administrative rights and this can make tinytex fail. This is usually a problem for users who are using a computer from their employees. You might need help from your local IT Department to get help with these issues and should try the steps shown above but make sure you have the rights to install everything.

It's also possible to try to install tinytex to a different folder where you know you have the admin rights, for example C:\My folder name\tinytex

Install tinytex in a specific folder with admin rights
tinytex::install_tinytex(dir = "C:\My folder name\tinytex")

 

Miscellaneous error messages

“Warning message: In has_crop_tools() : Tool(s) not installed or not in PATH: pdfcrop, ghostcript -> As a result, figure cropping will be disabled.”

Please try the following to resolve this issue

Please try the following to resolve this issue
tinytex::tlmgr_install("pdfcrop")

 

Error: LaTeX failed to compile chapter_0-1_introduction.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips.

In addition: Warning message:

In system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) :

  '"pdflatex"' not found

Execution halted

Try to install tinytex with the following command
tinytex::install_tinytex() 
Restart RStudio after the installation and try to compile to PDF. Try to to compile to HTML if the PDF fails. If the HTML compiles correctly we know that tinytex is working and have isolated the problem to PDF.