Type & Coercion Errors
Invalid argument type
Matches: invalid '([^']+)' argument
WHAT THIS ERROR MEANS
An argument you passed to a function is the wrong type. The function expected one type but received another.
HOW TO FIX IT
1. Read the function documentation with ?function_name.
2. Check what type the argument should be.
3. Convert your input to the correct type.
CODE EXAMPLES
BAD — THIS CAUSES THE ERROR
substr("hello", "2", "4") # indices should be numericGOOD — CORRECT APPROACH
substr("hello", 2, 4)Still stuck?
Paste your code in RChat and the AI will fix this error in context.
RELATED TYPE & COERCION ERRORS
Non-numeric argument to operator You tried to do math (like +, -, *, /) on something that isn't a number, such as...
Argument not numeric or logical A function that expects numbers (like mean, sum, sd) received non-numeric data s...
Cannot coerce type R tried to convert one data type to another but failed because the conversion is...
Replacement length mismatch You tried to assign a value to a column or vector, but the length of the new val...