Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use makeActiveBinding inside a package

Tags:

r

I simply need a R function like:

> la. <- function (envir = globalenv()) {ls(all = T, envir = envir) }`

with an active binding so I do need to type brackets

> makeActiveBinding('la', la., globalenv())

So that

> la
[1]  "la"  "la."

I now want to implement function la() and it bind la inside a package So that when I load the package, la is ready available.

How can I bind function la.() to the symbol la within the package environment?

What value shall I pass to the envir argument of function makeActiveBinding()

Thanks for any help

like image 732
Andrea Avatar asked Oct 15 '25 02:10

Andrea


1 Answers

This is probably something to do in the .onLoad function, something like this in your package:

NAMESPACE <- environment()

la. <- function(){ 
  ls(all = T, envir = globalenv())
}

.onLoad <- function(libname, pkgname) {
  makeActiveBinding("la", la., NAMESPACE)
}
like image 98
Romain Francois Avatar answered Oct 17 '25 17:10

Romain Francois



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!