R, RStudio, and RMarkdown
Installation
There are many errors you could come across while attempting to install R, RStudio, and
RMarkdown. Here are some troubleshooting tips if you aren’t sure where to begin:
• Before doing anything, restart the machine.
• Make sure R itself is working before checking RStudio. Look for R in the installed
programs or applications and open it up. It will just be a console. Try to generate a
dataset and make a histogram. If that works, continue with the troubleshooting steps.
• If you are on a machine running Windows 11, and it is forcing you to go to a store when
attempting to install R or RStudio, you are likely in S Mode, which you must exit. To do
so, follow this link.
• If you are on a MacOS machine, check the version number. Click the Apple logo in the
top-left and select “About this Mac”. The version number must be 13 or above.
o If you currently have an earlier version of MacOS and your device is compatible
with newer MacOS versions, upgrade to a newer version (at least MacOS 13).
o If you are unable to update your Mac, older versions of RStudio are available
for download here. Most of these RStudio versions are currently unsupported,
but may work on older versions of MacOS going back to MacOS Sierra (10.12)
• Check to see if there are any non-english characters in the R/RStudio installation path.
If there are, you will need to make a new account on your computer using only english
characters and reinstall R and RStudio on that account.
• If you cannot knit to pdf, make sure tinytex is installed. You install tinytex by entering
tinytex::install_tinytex() in the console.
• If you are on a windows machine, make sure that you are running RStudio as
administrator. To do so, when you open RStudio, right-click and select “Run as
administrator”.
Known Error Codes
If you get an error in your code, and you're not sure why, see if your error is listed below and
try the proposed solution. If it does not work, try restarting your machine, or re-installing the
software (both R and RStudio).
Error: attempt to apply non-function
This will often happen if you are trying to multiply without using a star. For example, if you’re
trying to multiply 5 and 3 by typing 5(3), you’ll get this error. In this case, you should be typing
5*3.
Error: figure margins too large
This usually means your plot window in the bottom-right is too small. Click and drag the
borders around the plot window to expand it as much as you can and try again.
Line 2: Failed to parse the inline R code…
This likely means you attempted to modify the “date” information in Line 2 on a worksheet or
assignment. Leave this line unchanged; it automatically sets the date for you when you knit your
file.
Error in ______: object ______ not found
This usually means that you are referencing a dataset / vector that hasn’t been defined yet.
Make sure you run the line of code where the object has been defined. If you are getting this
error while attempting to knit an RMarkdown file to PDF, check through your code chunks and
make sure you’ve imported your data and defined your variables in the code chunks.
Bad CPU type in executable
For Mac users, this may mean that you have installed the wrong version of R. Note that there
are two versions of R that may be downloaded: the Apple silicon (M1/M2) version, and the Intel
version. If you are not on an M1/M2 mac, follow the steps below:
1. Quit RStudio and uninstall R (you can leave RStudio installed).
2. Download and install the version of R for Intel Macs on this website.
3. Continue in RStudio; you should be able to knit now.
If you are on an M1/M2/M3 Mac, then you need to install Rosetta. To do so:
1. Quit RStudio and uninstall R (you can leave RStudio installed).
2. Download and install the version of R for Apple silicon Macs on this website.
3. When you start installing R, it will automatically install Rosetta for you. Once Rosetta is
installed, you can continue in RStudio.
LaTeX Error: Unicode character _ not set up for use with LaTeX.
This means that you have used an illegal character somewhere in your RMarkdown file. For
example, you may have entered a character with an accent or copied a Greek / mathematical
character. Make sure you are only entering the standard characters on your keyboard when
filling out the RMarkdown file.
To find where the symbol is in your document, click “Edit” > “Find…” in the top toolbar. Then
copy the symbol from the error and paste it into the Find box. Delete or replace the symbol
with an appropriate symbol from your keyboard.
LaTeX Math Errors
! Missing $ inserted.
This can happen if LaTeX is not properly surrounded by dollar signs. Double check that you
have closed all your LaTeX expressions with $ or $$. Even if there is just a space between code
and $, you may receive this error. The error will tell you which LaTeX code is the problem; find
it in your document and close it with a dollar sign or remove unnecessary spacing.
! Undefined control sequence.
This error can happen when a function in LaTeX is misspelled. For example, you type \ddfrac{}
instead of \dfrac{}. The error will tell you which function in your R document is the problem; find
it and fix any spelling errors.
! Missing \endcsname inserted. or ! Missing number, treated as zero.
You may also see this error if a LaTeX command is misspelled. For example, you type \alph ins
tead of \alpha. The error will tell you which function in your R document is the problem; find it
and fix any spelling errors.