Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8757327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:16:30+00:00 2026-06-13T14:16:30+00:00

I observed a different between an interactive and non-interaction R session about traceback() which

  • 0

I observed a different between an interactive and non-interaction R session about traceback() which I do not understand. For the code below, it will produce an error, but in an interactive R session, I can see the traceback information, whereas if I save the code to test.R and call it via Rscript test.R or R -f test.R, I can no longer see the traceback:

f = function() {
  on.exit(traceback())
  1 + 'a'
}
f()

In an interactive R session:

> f = function() {
+   on.exit(traceback())
+   1 + 'a'
+ }
> f()
Error in 1 + "a" : non-numeric argument to binary operator
1: f()

Non-interactive execution:

$ Rscript test.R 
Error in 1 + "a" : non-numeric argument to binary operator
Calls: f
No traceback available 
Execution halted

I did not see an explanation in ?traceback, and I’m wondering if there is a way to enable traceback for non-interactive R sessions. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:16:31+00:00Added an answer on June 13, 2026 at 2:16 pm

    With default values of its arguments, traceback() will look for an object named .Traceback in the baseenv() for information on the call stack. It looks (from src/main/errors.c) like .Traceback is only created if, among other conditions, R_Interactive || haveHandler, suggesting that this object is not created during non-interactive sessions. If there is no object named .Traceback, you will get the message “No traceback available”.

    However, by passing a non-NULL value to the x argument of traceback(), one can obtain information about the call stack from a non-interactive session. With a non-zero integer value (indicating the number of calls to skip in the stack), c-level functions (R_GetTraceback) are called to investigate the call stack instead of looking in .Traceback.

    So there are a couple ways to obtain traceback information in a non-interactive session:

    f = function() {
      on.exit(traceback(1))
      1 + 'a'
    }
    f()
    

    Or, setting options as Brandon Bertelsen suggested

    options(error=function()traceback(2))
    

    The different values passed to x in the two examples account for the different number of functions to skip

    1. In the on.exit example, traceback(1) skips the call to traceback().

    2. In the example setting options, there is an extra anonymous function that calls traceback() which should/could also be skipped.

    In the example in the OP, there’s not much more information gained by using traceback() compared to the automatic traceback provided in the case of an error in a non-interactive session. However, with functions that take (and are passed) arguments, using traceback() will be much more informative than the standard presentation of the call stack in the non-interactive session.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I observed something last week that I did not expect, and will describe below.
I've observed a difference in behavior between the new library in Visual Studio 11
I've first observed this issue in a production code, then made a prototype: import
I have observed that, very infrequently, Internet Explorer (7 or 8, it does not
I observed some inconsistency between two compilers (g++ 4.5, VS2010 RC) in the way
I observed the following behavior while working with the perl code base (on branch
How do I handle references between Fragments showing list of data and different threads/classes
I feel that i don't fully understand difference between KVO and NSNotification... They seem
There are N different classes that can be observed in my problem and my
Scala Where can differences between a class and a type be observed in Scala

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.