round(3.14159, 2Error in parse(text = input): <text>:2:0: unexpected end of input
1: round(3.14159, 2
^
Everyone runs into the same handful of errors when they’re getting started with functions. Recognizing them quickly will save you a lot of frustration. Each example below is broken on purpose, try to spot the problem before reading the explanation.
Error in parse(text = input): <text>:2:0: unexpected end of input
1: round(3.14159, 2
^
Explain: every opening parenthesis needs a matching closing parenthesis. R will often show a + prompt (instead of an error) and appear to “hang” while it waits for you to finish the expression. If that happens, you’re almost always just missing a closing ).
Explain: R is case-sensitive and doesn’t guess at typos. maen() doesn’t exist, so R tells you it “could not find function.” Double-check your spelling (and capitalization) whenever you see this error.
Explain: the round() function expects an argument called digits (plural), not digit. R doesn’t recognize digit as a valid argument name for round(), so it raises an error rather than guessing what you meant.
Explain: without quotation marks, R assumes hello is the name of an existing object, and complains that it can’t find one. To create a piece of text (a character string), you must wrap it in quotes: x <- "hello".
Each line below contains exactly one mistake from the list above (or no mistake at all). Predict what’s wrong with each one, then check the solution.
sum(1, 2, 3 is missing a closing parenthesis.sqrt(16) has no mistake — it runs fine!Round(2.71828, 2) misspells round() with a capital R. R function names are case-sensitive, so Round isn’t recognized.mean(x, na.rm = "yes please") supplies the wrong type of value for na.rm, which expects TRUE or FALSE, not a piece of text. We’ll cover exactly how you find out what type of value an argument expects once we look at documentation later in this module.Which of the following would cause an error, and why?
Sum(1:5)sum(1:5sum(1:5)sum(nums = 1:5)Test each one in the editor to check your reasoning.