select(penguins, bill_length_mm)
#> Error in select(penguins, bill_length_mm): could not find function "select"
lenght(1:10)
#> Error in lenght(1:10): could not find function "lenght"
Day 1 - Introduction to Data Analysis with R
Freie Universität Berlin - Theoretical Ecology
March 14, 2025
When learning a programming language, you have to be prepared to spend a lot of time fixing bugs. Don’t worry: It’s not you, it’s just how programming works!
Debugging can be annoying and we can’t avoid it, but …
… it’s an effective learning experience (I actually learned the most from debugging my code)
… it will get easier over time
… there are some debugging techniques to decrease the time in stages 2-7
… if nothing helps, there are great people all over the internet willing to help
and how to deal with them
“Could not find function” errors have two main reasons:
library()
or call the function with packageName::functionName()
lenght()
instead of length()
)variableA
but you try to access variable_A
)print(hello)
looks for a variable named hello
but instead you wanted to print the string print("hello")
Sometimes R crashes completely and you see this:
There is no fix but to start a new session
Make sure to save your scripts regularly!
+
R is not running code anymore and the console only prints +
if you try to execute a command.
Escape
. Then you should see the >
sign instead of +
again.R can give you warnings for many reasons, e.g.
NA
values in your data and try to plot themWarnings are no errors and can sometimes be ignored but:
A step by step guide
Often, you don’t need to do all the steps but a systemmatic approach to bug fixing is very helpful.
str()
?functionName
: Did you use the function correctly? Did you forget an argument?Tip
Change language of R messages to English with Sys.setenv(LANGUAGE='en')
There are plenty of places where you can ask for help online. Some common and good options are:
Ask a question on Stack Overflow
Ask in the R Discord server
But: You have to make sure that before, you tried all the other 5 steps.
To ask questions online, you have to learn how to ask a clear question including a reproducible example
Look here for more info on how to ask a good question about R
Selina Baldauf // Common errors