[R] Is there a way to get R script line number

William Michels wjm1 at caa.columbia.edu
Fri Apr 7 11:28:04 CEST 2017


Hi Brad,

Some of the debugging functions may be of use. You can look at trace()
or setBreakpoint(). But I believe Bert is correct in saying your
concept of a "Line Number" and R's concept of a "Line Number" will
differ.

Finally, you can look at the function findLineNum(), which can be
called external to your source code file (not embedded as in your
example).

>?debug

HTH,

Bill

William J. Michels, Ph.D.



On Thu, Apr 6, 2017 at 12:30 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
> I believe the answer is: No. "Line number" is an ambiguous concept.
> Does it mean physical line on a display of a given width? a line of
> code demarcated by e.g. <CR> ; a step in the execution of script (that
> might display over several physical lines?)
>
> However, various IDE's have and display "line numbers," so you might
> try researching whichever one that you use.
>
> (Note: Correction/clarification requested if I am wrong on this).
>
> -- Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, Apr 6, 2017 at 11:59 AM, Brad P <bpschn01 at gmail.com> wrote:
>> Hello,
>>
>> Is there a way to get the current line number in an R script?
>>
>> As a silly example, if I have the following script and a function called
>> getLineNumber (suppose one exists!), then the result would be 3.
>>
>> 1 # This is start of script
>> 2
>> 3 print( getLineNumber() )
>> 4
>> 5 # End of script
>>
>> Thanks for any ideas!
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list