[R] Controlling visibility of top-level functions

2014-01-31 Thread Paul A. Steckler
I'm fairly new to R, and have checked the R FAQ and done an RSiteSearch for help
on this topic, to no avail.

I want to write some R code that has functions at the top-level that
are not visible when
the code is loaded. So in

  fun1 - function(...)  { ... }

  fun2 - function(...)  { ... fun1 ...}

I'd like fun2 to be callable, but have fun1 be invisible. That is, the
scope of fun1 is
limited to the file in which it's defined.

In Python, I believe that prepending an underscore to a variable name
limits its scope in this way.
Is there a similar mechanism in R?

-- Paul

__
R-help@r-project.org mailing list
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.


Re: [R] Controlling visibility of top-level functions

2014-01-31 Thread Paul A. Steckler
Thanks for the suggestions.

I'm going to need to create an R package, eventually, so I'll use that
mechanism to control visibility.

-- Paul

On Fri, Jan 31, 2014 at 11:13 AM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
 On 31/01/2014 1:46 PM, Paul A. Steckler wrote:

 I'm fairly new to R, and have checked the R FAQ and done an RSiteSearch
 for help
 on this topic, to no avail.

 I want to write some R code that has functions at the top-level that
 are not visible when
 the code is loaded. So in

fun1 - function(...)  { ... }

fun2 - function(...)  { ... fun1 ...}

 I'd like fun2 to be callable, but have fun1 be invisible. That is, the
 scope of fun1 is
 limited to the file in which it's defined.

 In Python, I believe that prepending an underscore to a variable name
 limits its scope in this way.
 Is there a similar mechanism in R?


 There are a couple ways.

 The heavyweight way is to write a package that exports fun2 but not fun1.
 fun2 can see fun1, but the rest of the world can't.
 Scope isn't limited to one file, any function in the package can see it.

 The lightweight way is to define fun1 and fun2 in a local scope, e.g.

 fun3 - local({


   fun1 - function(...)  { ... }

   fun2 - function(...)  { ... fun1 ...}
   fun2
 })

 This way fun1 and fun2 can see each other but nobody else can see them, and
 fun3 is a copy of fun2 that is visible in the workspace.  You don't need a
 third name, I just changed it to make the explanation easier.

 Duncan Murodch





__
R-help@r-project.org mailing list
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] Distributing R byte code

2013-05-10 Thread Paul A. Steckler
Hi,

  I've used R just a little bit, and I couldn't find an answer to my
questions via Web search.

  I'm aware of Luke Tierney's byte code compiler for R, and the
compile package, and I have some questions about its use. I want to
take some R code, create byte code for it, and distribute it, rather
than the original R source.

  - Is there a way to generate bytecodes from the (shell) command
line, or do I need to start an R session? I'd like to automate
generating byte code.

  - Are the generated byte codes restricted to use for a particular
version of R?

  - I'd appreciate any advice about using loadcmp, like what
environment argument to use.

  Thanks for any help.

-- Paul

__
R-help@r-project.org mailing list
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.