unlockEnvironment: Unlock an R Package Enviroment and Assign an Object to the R...

Description Usage Arguments Value Author(s) References Examples

View source: R/RcppExports.R

Description

Of unlockEnvironment, unlock a non-base package environment. Note: R package base is unlocked (by design)

Of lsNamespaceInfo, from the name of a namespace, return a character vector of all objects

Of AllInfoNS, from the name of a namespace, return information

Of forceAssignInNamespace, force the assignment of a new item into a namespace. Adapted from Rcpp. Based on the original function forceAssignMyNamespace by Willem Ligtenberg.

Usage

1
2
3
4
5
6
7

Arguments

env

Environment. Default none. Required.

ns

String. Default none. Required. Name of a namspace

...

dots. Passed to ls

x

String. Required. Default none. Name of the symbol/function

value

R Object. Default none. Required. New value of the parameter x symbol/function

namespace

String. Default none. Required. Name of the namespace to assign parameter x into.

Value

Of unlockEnvironment, Logical. TRUE if this package environment has been successfully unlocked. FALSE otherwise.

Of lsNamespaceInfo, return a character vector of objects in a namespace

Of AllInfoNS, return lists and sublists of information about the namespace

Of forceAssignInNamespace, silently assign object x (from parameter x) intoto the namespace non-exported objects collection

Author(s)

Willem Ligtenberg is the author of unlockEnvironment

Andre Mikulec

Andre Mikulec is the author of AllInfoNS

Willem Ligtenberg is the author of forceAssignInNamespace/forceAssignMyNamespace

References

unlockEnvironment function https://github.com/openanalytics/Rango/blob/adc99e077b71c8c6826cabb7ff1266050898718a/Rango/src/unlockEnvironment.cpp

envir.c in the R 2.15.1 source (still in R 3.3.1) https://github.com/SurajGupta/r-source/blob/a28e609e72ed7c47f6ddfbb86c85279a0750f0b7/src/main/envir.c

forceAssignMyNamespace by Willem Ligtenberg https://github.com/openanalytics/Rango/blob/adc99e077b71c8c6826cabb7ff1266050898718a/Rango/R/utils.R

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
## Not run: 
#
# something not-on-the-search() path
#
requireNamespace("RPostgreSQL")

getNamespace("RPostgreSQL")
<environment: namespace:RPostgreSQL>

environmentIsLocked(getNamespace("RPostgreSQL"))
[1] TRUE

unlockEnvironment(getNamespace("RPostgreSQL"))
[1] TRUE

forceAssignInNamespace("prnt", function(x) {print(x)}, namespace = "RPostgreSQL")
RPostgreSQL::prnt("HelloEveryWhere")
Error: 'prnt' is not an exported object from 'namespace:RPostgreSQL'

RPostgreSQL:::prnt("HelloEveryWhere")
[1] "HelloEveryWhere"

assign("prnt","prnt", envir = AllInfoNS("RPostgreSQL")$exports)
RPostgreSQL::prnt("HelloEveryWhere")
[1] "HelloEveryWhere"

## End(Not run)
## Not run: 
#
# something on the search() path
#
library(RSQLite)

getNamespace("RSQLite")
<environment: namespace:RSQLite>

environmentIsLocked(getNamespace("RSQLite"))
[1] TRUE

unlockEnvironment(asNamespace("RSQLite"))
[1] TRUE

forceAssignInNamespace("prnt", function(x) {
  print(x)
}, namespace = "RSQLite")

RSQLite::prnt("HelloEveryWhere")
Error: 'prnt' is not an exported object from 'namespace:RSQLite'

RSQLite:::prnt("HelloEveryWhere")
[1] "HelloEveryWhere"

# promote that function to be exported
assign("prnt","prnt", envir = AllInfoNS("RSQLite")$exports)
RSQLite::prnt
function(x) {print(x)}

RSQLite::prnt("HelloEveryWhere")
[1] "HelloEveryWhere"

## End(Not run)

AndreMikulec/econModel documentation built on June 30, 2021, 9:48 a.m.