Displaying 20 results from an estimated 26 matches for "unlockbinding".
2013 Feb 07
1
assignInNamespace to create a setwd() replacement: how to use unlockBinding()?
...ese all worked for all R versions up to R 2.15.0, where it began to
break as follows:
> source("setwd-new.R")
Error in utils::assignInNamespace("setwd", function(dir) { :
locked binding of ?setwd? cannot be changed
>
I understand what the error means, and I think that unlockBinding()
somewhere in my code gives a solution,
but I don't see where or how.
I should also add that in my actual .Rprofile, I source these functions
into a local environment & attach
so they are always available, but don't clutter up ls()
.my.env <- local({
# all my local definitions
}...
2011 May 31
1
assignInNamespace and new bindings
...R/objects.R (revision 56024)
+++ src/library/utils/R/objects.R (working copy)
@@ -252,8 +252,9 @@
stop("environment specified is not a package")
ns <- asNamespace(substring(nm, 9L))
} else ns <- asNamespace(ns)
- if(bindingIsLocked(x, ns)) {
- unlockBinding(x, ns)
+ new_binding <- !exists(x,ns)
+ if( new_binding || bindingIsLocked(x, ns)) {
+ if(!new_binding) unlockBinding(x, ns)
assign(x, value, envir = ns, inherits = FALSE)
w <- options("warn")
on.exit(options(w))
Romain
--
Romain Francoi...
2009 Apr 20
1
Sharing variables in seperate workspace
...nding for '.FOO'
The double arrow, I use because <- does not affect the contents of .FOO
after the function has run. I don't know how I can use assign in this
case. I don't know a name for my package's environment. I have tried
with my package's name in both assign() and unlockBinding(), but my
package's name is not recognized as an environment (neither beginning
with a dot.). I also tryed unlockBinding() in the NAMESPACE file.
I don't know if this is normal, but I get
<environment: R_GlobalEnv>
from print(parent.frame()) and things like
<environment: 0x8df2ad0...
2013 Jul 26
1
How to best implement package options?
...like
pls.options()), and store a list of options in the package name space.
This avoids any name collisions, but users have to relate to several
options interfaces (the ones I've seen work mostly the same as the
standard options(), though).
AFAIK, this solution neccessitates calling unlockBinding() on the
option list, or using assignInMyNamespace() to update it.
3) Finally, I've found one package ('pkgmaker') that implements a
general mechanism that can be used by other packages to create package
options. The mechanism creates options()-like functions in the
package...
2009 Jan 23
1
overwriting '<-' and infinite recursions
...I need to overwrite
it is complicated and not easy to tell in a few words; but this seems
the only clean option other than hacking R's core source code. My code
looks like:
# in .onLoad of a package; or if you want to test, put it in a function
env <- as.environment('package:base')
unlockBinding('<-',env)
assign('<-', newAssign, envir=env)
.Internal(lockBinding(as.name('<-'), env))
#not using lockBinding directly because it calls '<-'
It gave me this error: Error: evaluation nested too deeply: infinite
recursion / options(expressions=)?
Any su...
2011 Aug 08
1
Overwriting imported function in another package
...ackages
library(grid);
library(lattice);
library(ggplot2);
#create the modified function.
hookfun <- deparse(body(plot.new))[1:6]
oldfun <- deparse(body(grid::grid.newpage))[-1];
newfun <- grid::grid.newpage;
body(newfun) <- parse(text=c(hookfun, oldfun));
#overwrite it in the package
unlockBinding("grid.newpage", as.environment("package:grid"))
assign("grid.newpage", newfun, pos="package:grid")
#this seems ok:
get('grid.newpage', as.environment("package:grid"));
get('grid.newpage', as.environment("package:lattice"))...
2015 Jan 21
2
reducing redundant work in methods package
...- new.env()
for (fname in funs) {
# Make placeholder for input/output for future runs of this function
TEST_ENV[[fname]] = list() # Actually probably not necessary, will
just be c(NULL, list(first result)) the first time
# Construct test version of function
unlockBinding(fname, ns)
fun = get(fname, envir=ns, mode="function")
funbody = deparse(body(fun))
newfun <- fun
newfun.body = c(
sprintf("fname = '%s'", fname),
"TEST_INFO = list()",
"TEST_INF...
2012 Dec 11
1
Reassign functions called by other functions in package graphics
...w resp.. So far I've tried:
reassignInPackage from R.utils: reassignInPackage("plot.default","graphics",my.plot.default) gives "Error in assignInNamespaceT(name, value, ns = pkgName, envir = env) : locked binding of ?plot.default? cannot be changed", even after
unlockBinding("plot.default",as.environment("package:graphics"))
assignInNamespace seems to almost work. Here's what I enter:
plot.default<-function(...){cat("Entered plot.default")}
plot.new<-function(...){cat("Entered plot.new")}
assignInNamespace("plot...
2018 Dec 21
2
Bug report: R.home() cause package Rcpp failed executing sourceCpp, similar bug are labeled "BUG 16660" since 2016 and here I could provide a solution that tested in my laptop.
...t;)
Error in system(cmd, intern = !showOutput) : 'D:/Program' not found
Error in system(cmd, ignore.stderr = TRUE, intern = TRUE) :
'D:/Program' not found
Code is tested in both R 3.5.1 and Microsoft R Open 3.5.1.
I find a temp solution, is to copy such words into Rprofile:
unlockBinding("R.home", baseenv())
utils::assignInNamespace("R.home",function (component = "home")
{
rh <- .Internal(R.home())
paste0('"',switch(component, home = rh, bin = if (.Platform$OS.type ==
"windows" && nzchar(p <- .Platfo...
2015 Jan 21
2
reducing redundant work in methods package
...utput for future runs of this
>> function
>>
>> TEST_ENV[[fname]] = list() # Actually probably not necessary,
>> will
>> just be c(NULL, list(first result)) the first time
>>
>> # Construct test version of function
>>
>> unlockBinding(fname, ns)
>>
>> fun = get(fname, envir=ns, mode="function")
>>
>> funbody = deparse(body(fun))
>>
>> newfun <- fun
>>
>> newfun.body = c(
>>
>> sprintf("fname = '%s'&qu...
2011 Jan 26
1
Problem with "setMethod" in R package
...;rothC>("rothC")
.constructor()
...
}
######### FILE rcpp_rothC.R #########
Rcpp_rothC.plot <- function(x,y,...) { ... }
########## FILE zzz.R ##########
.NAMESPACE <- environment()
rothC <- new( "Module" )
.onLoad <- function(libname, pkgname) {
unlockBinding( "rothC" , .NAMESPACE )
assign( "rothC", Module( "rothC" ), .NAMESPACE )
setMethod(f="plot",signature(x="Rcpp_rothC",y="missing"),definition=Rcpp_rothC.plot,where=.GlobalEnv);
lockBinding( "rothC", .NAMESPACE )
}
.onAtt...
2024 Mar 21
1
[External] Re: Building Packages. (fwd)
...isible.
You can fix all of these with something like
local({
up <- match("package:utils", search())
detach("package:utils")
library(utils, pos = up)
})
or just install.packages with
local({
up <- match("package:utils", search())
unlockBinding("install.packages", pos.to.env(up))
assign("install.packages", utils::install.packages, "package:utils")
lockBinding("install.packages", pos.to.env(up))
})
Best,
luke
On Thu, 21 Mar 2024, Duncan Murdoch wrote:
> Yes, you're right. The ve...
2009 Oct 04
1
Modify base R functions in Rprofile.site
Hi everyone,
I want to modify two base R functions 'parse' and 'deparse'
immediately after R has started, so I added some code in the file
'Rprofile.site' under the 'etc' directory. Here is a simple example:
parse=function(...){
base::parse(...)
}
I'll get an error when I start R as follows:
Error: cannot change value of locked binding for
2011 Jan 23
0
setMethod call in package code using Rcpp
...;rothC>("rothC")
.constructor()
...
}
######### FILE rcpp_rothC.R #########
Rcpp_rothC.plot <- function(x,y,...) { ... }
########## FILE zzz.R ##########
.NAMESPACE <- environment()
rothC <- new( "Module" )
.onLoad <- function(libname, pkgname) {
unlockBinding( "rothC" , .NAMESPACE )
assign( "rothC", Module( "rothC" ), .NAMESPACE )
setMethod(f="plot",signature(x="Rcpp_rothC",y="missing"),definition=Rcpp_rothC.plot,where=.GlobalEnv);
lockBinding( "rothC", .NAMESPACE )
}
.onAtt...
2013 Feb 27
0
How to specify ff object filepaths when reading a CSV file into a ff data frame.
...t
}
else {
do.call("as.ff", c(list(xi, vmode = vmodes[[i]]),
col_args))
}
}, ...)
names(ret) <- names(x)
do.call("ffdf", c(ret, list(row.names = rnam), l))
}
# |||||||||||||||||||||||||||||||| hook |||||||||||||||||||||||||||||||||
library(methods)
unlockBinding("as.ffdf.data.frame", as.environment("package:ff"))
assignInNamespace("as.ffdf.data.frame",
my.as.ffdf.data.frame,
ns="ff", envir=as.environment("package:ff"))
assign("as.ffdf.data.frame", my.as.ffdf.data....
2015 Jan 21
0
reducing redundant work in methods package
...t; # Make placeholder for input/output for future runs of this
> function
>
> TEST_ENV[[fname]] = list() # Actually probably not necessary, will
> just be c(NULL, list(first result)) the first time
>
> # Construct test version of function
>
> unlockBinding(fname, ns)
>
> fun = get(fname, envir=ns, mode="function")
>
> funbody = deparse(body(fun))
>
> newfun <- fun
>
> newfun.body = c(
>
> sprintf("fname = '%s'", fname),
>
> "...
2008 Mar 13
3
Sealed for setGeneric
Hi the list
When two setGeneric occurs on the same function, the second erage the
first and erase all the function previously define.
Is it possible to prevent that ? Is it possible to declare a setGeneric
that can not be erased later ?
Something like the |sealed for setMethod...|
||
|Thanks|
||
Christophe
2024 Mar 21
1
[External] Re: Building Packages. (fwd)
...local({
> up <- match("package:utils", search())
> detach("package:utils")
> library(utils, pos = up)
> })
>
> or just install.packages with
>
> local({
> up <- match("package:utils", search())
> unlockBinding("install.packages", pos.to.env(up))
> assign("install.packages", utils::install.packages, "package:utils")
> lockBinding("install.packages", pos.to.env(up))
> })
>
> Best,
>
> luke
>
> On Thu, 21 Mar 2024, Duncan Murd...
2015 Jan 22
0
reducing redundant work in methods package
...t;> function
>>>
>>> TEST_ENV[[fname]] = list() # Actually probably not necessary,
>>> will
>>> just be c(NULL, list(first result)) the first time
>>>
>>> # Construct test version of function
>>>
>>> unlockBinding(fname, ns)
>>>
>>> fun = get(fname, envir=ns, mode="function")
>>>
>>> funbody = deparse(body(fun))
>>>
>>> newfun <- fun
>>>
>>> newfun.body = c(
>>>
>>>...
2006 May 19
1
UseMethod infelicity
If I do
> example(lm)
...
> mycoef <- function(object, ...) UseMethod("coef", object)
> mycoef(lm.D9)
Error in mycoef(lm.D9) : no applicable method for "coef"
which is pretty surprising, as coef has a default method.
After a bit of digging, this comes from do_usemethod having
defenv = environment where the generic was defined */
defenv =