open-interpreter icon indicating copy to clipboard operation
open-interpreter copied to clipboard

R Function Return Values Return NULL Instead of Actual Values

Open endolith opened this issue 4 months ago • 0 comments

Describe the bug

Description

When running R code in Open Interpreter that defines and calls functions, the function's return value is often captured as NULL instead of the actual computed value. Simple print statements and direct assignments work fine, but function calls often fail to capture return values properly.

What Works

  • Simple prints: print("Hello, world!")
  • Direct calculations: normalized_x <- (x - min(x)) / (max(x) - min(x))

What Fails

  • Function return values show as NULL when using implicit returns

Technical Details

The preprocessing in interpreter/core/computer/terminal/languages/r.py wraps all code in tryCatch() blocks (line 32-38), which suppresses function return values. The tryCatch wrapper is intended for error handling but ends up suppressing normal R function returns.

Suggested Fix

Modify the tryCatch() wrapper in r.py to preserve and display return values or use a different error handling approach that doesn't suppress returns.

Reproduce

Steps to Reproduce

  1. Start an Open Interpreter session
  2. Ask the AI to create a normalization function in R, for example:
normalize <- function(x) {
    (x - min(x)) / (max(x) - min(x))
}
result <- normalize(c(1, 2, 3, 4, 5))
print(result)
  1. Observe output shows NULL instead of expected normalized values

Expected behavior

Expected Behavior

Function return values should be captured and displayed correctly, regardless of whether they use implicit or explicit returns.

Actual Behavior

Function return values are captured as NULL when using implicit returns (which is the normal R convention - the value of the last evaluated expression).

Screenshots

No response

Open Interpreter version

0.4.3 (develop branch)

Python version

3.10.13

Operating System name and version

Windows 10

Additional context

No response

endolith avatar Oct 27 '25 01:10 endolith