[Rd] Locating code that is outside of functions in R scripts

From: <gheine_at_mathnmaps.com>
Date: Wed, 23 Dec 2009 17:04:09 -0700

Working with a number of scripts (text files with R commands) that I

"source" into R sessions from time to time.

The source() command is most convenient (at least for me)

if it only loads function definitions, and doesn't otherwise change the

interactive environment. For example, I might have a file that looks like

func1<-function() {

  code

  code

  code

  }

# this is a comment

A<-"this is code outside the function definitions";

func2<-function() {

   code

# a comment with a spurious }

   code

   code

   }

I would like a quick-and-dirty script that finds the line beginnning with

"A", since it is R code outside of any function definition.

On the other hand it would ignore the two comment lines, and would not be

fooled by the spurious "}" in the second comment line.

Probably not too hard to put something like this together, but am making

this post in case it is something that has already been done.

Thanks!



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 24 Dec 2009 - 00:08:06 GMT

This archive was generated by hypermail 2.2.0 : Thu 24 Dec 2009 - 06:11:11 GMT