Skip to content

R Function Return Values Return NULL Instead of Actual Values #1655

@endolith

Description

@endolith

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions