Appendix C — Troubleshooting & FAQ

Errors are a normal part of writing R code – even experienced programmers see them every day. This page collects the errors and issues that beginners run into most often, with tips for fixing them yourself.

TipGeneral advice

Read error messages from the top down, and look for the last line first – it usually summarises the problem. Then check whether you can find the line of code mentioned in the error. If you’re stuck, search for the exact error message online (e.g. on Stack Overflow), or check the Glossary for unfamiliar terms.

C.1 could not find function "..."

What it means: R doesn’t recognise the function name you typed.

Common causes:

  • Typo in the function name. R is case-sensitive, so Read_csv() is not the same as read_csv().
  • The package isn’t loaded yet. Functions like read_csv() (from readr) or ggplot() (from ggplot2) only become available after you run library(readr) or library(ggplot2). See R Packages and Libraries.
  • The package isn’t installed. If library(packageName) itself gives an error like there is no package called 'packageName', you need to run install.packages("packageName") first.

C.2 object '...' not found

What it means: R doesn’t recognise the variable (object) name you used.

Common causes:

  • Typo or different capitalisation. my_data and My_Data are different objects in R. See the “Common Mistakes” box in Basic R Syntax and Operations.
  • The object hasn’t been created yet (or the chunk wasn’t run). In R Markdown / Quarto documents, code chunks must be run in order – if you skipped an earlier chunk, objects it created won’t exist yet.
  • The object was removed. If you ran rm(my_data) or my_data <- NULL, the object (or its contents) is gone and needs to be recreated.

C.3 Mismatched quotes, parentheses, or brackets

What it means: R is still waiting for you to “close” something you opened – often shown as a + prompt in the console instead of the usual >, or an error like unexpected end of input or unexpected ')'.

Common causes and fixes:

  • Count your brackets. Every (, [, and { needs a matching ), ], or }. RStudio highlights matching brackets when your cursor is next to one – use this to spot the mismatch.
  • Check your quotes. A string must start and end with the same type of quote ("..." or '...'). A stray " partway through your code will make R think the string continues onto the next line.
  • Stuck at a + prompt? Press Esc in the console to cancel the incomplete command, then fix and re-run it.

C.4 package not found before library()

What it means: You tried to library(packageName) a package that hasn’t been installed on this computer yet.

Fix: Run install.packages("packageName") once (it needs an internet connection), then library(packageName) will work for the rest of this session and every future session. See R Packages and Libraries.

C.5 Working directory and file path issues

What it means: read_csv() (or another import function) gives an error like cannot open file or No such file or directory.

Common causes and fixes:

  • Check your working directory with getwd(). Relative paths (like "data/fruit_data.csv") are interpreted relative to this folder.
  • Check the path is relative to the right place. If your file is in data/ but your script is in sessions/, you may need "../data/fruit_data.csv" (the ../ means “go up one folder first”). See “Different Scenarios for Importing Data” in Importing Data.
  • Check the file extension and spelling. Windows sometimes hides file extensions, so a file you think is named data.csv might actually be data.csv.txt.
  • Avoid OneDrive/cloud-synced folders if possible. These can occasionally cause file-locking issues that produce confusing errors.

C.6 Still stuck?

  • Use ?functionName or help(functionName) to check a function’s arguments – see Help and Documentation.
  • Search for the exact error message on Stack Overflow or the RStudio Community.
  • Take a break! A surprising number of bugs become obvious after stepping away for a few minutes.