Get Started →
Type & Coercion Errors

Argument of length zero

Matches: argument of length 0

WHAT THIS ERROR MEANS

A function received an empty (zero-length) argument. This often happens when a variable is NULL or when subsetting returns nothing.

HOW TO FIX IT

1. Check if the variable is NULL or empty with length().

2. Add a guard: if (length(x) > 0) { ... }.

3. Trace back where the variable was created to find why it's empty.

CODE EXAMPLES

BAD — THIS CAUSES THE ERROR
x <- c()
if (x > 0) print("positive")  # length 0
GOOD — CORRECT APPROACH
x <- c()
if (length(x) > 0 && x > 0) print("positive")

Still stuck?

Paste your code in RChat and the AI will fix this error in context.

Try RChat Free →

RELATED TYPE & COERCION ERRORS