Displaying 20 results from an estimated 1000 matches similar to: "(PR#7495) Function Body / Formals Bug"
2005 Jan 12
0
Function Body / Formals Bug (PR#7495)
I'd like to report two bugs in the R function definitions, the first
slightly problematic, the second likely unimportant. Both of these are
reproducible on both Windows and Linux, R 2.0.1
First Bug:
> a <- new("function")
> formals(a) <- alist(a=, b=, c=, d=)
> a
function (a, b, c) ## the d argument disappeared!
> formals(a) <- alist(a=, b=, c=, d=)
> a
2016 Mar 29
0
body(NULL) <- something; ditto formals() -- should not work
Hi,
On 03/07/2016 09:26 AM, Martin Maechler wrote:
> I'm proposing to signal an error (from R >= 3.3.0) in such
> examples -- which do "work" in R 3.2.x and earlier :
>
>> f <- NULL; body(f) <- quote(sin(a+1)); f
> function ()
> sin(a + 1)
> <environment: 0x48f9798>
>
This works because formals() (the getter) works on things that are
not a
2016 Mar 07
2
body(NULL) <- something; ditto formals() -- should not work
I'm proposing to signal an error (from R >= 3.3.0) in such
examples -- which do "work" in R 3.2.x and earlier :
> f <- NULL; body(f) <- quote(sin(a+1)); f
function ()
sin(a + 1)
<environment: 0x48f9798>
> g <- NULL; formals(g) <- alist(x = pi, y=); g
function (x = pi, y)
NULL
<environment: 0x4e6dfe8>
>
The proposal is that the underlying C
1999 Mar 29
3
problems with formals and get (PR#151)
With 0.63.3, try
test <- function(){
fn <- function(a) print("hello")
print(is.function(fn))
print(names(formals("fn")))}
test()
if fn is not quoted in the last line of test, it works properly.
test <- function(){
fn <- function() print("hello")
formals(fn) <- alist(a=,b=)
return(fn)}
formals(test())
now try with line 3 of test changed to
2007 Jun 26
1
slight anomaly in formals<- ? (PR#9758)
Hi,
The R input/output after the following paragraph is from a session with
version.string R version 2.4.0 Patched (2006-11-23 r39958).
The last element, x$c, of x has no value and after the assignment of x to the
formals of f, x$c does not become a formal argument of f. The second assignment
does the job. It seems that x$c actually becomes the body of f after the first
assignment. There is no
2009 Jul 24
1
Most elegant way to use formals() in building functions
Dear Group:
I want to create a function having a ... argument and to have the
default arguments evaluated, as thus:
g <- function(a, b, ...) a+b
formals(g) <- alist(a=,b=2+3,...=)
g
function (a, b = 2 + 3, ...)
a + b
But I want the default argument for b to be evaluated as 5. How can
this be done? Note: My real need is for a more complex expression to be
evaluated for the default
2009 Oct 01
1
inverse currying
Dear list,
I have the following function,
sugar = function(fun, id = "id"){
ff <- formals(fun)
if( id %in% names(ff))
stop("id is part of args(fun)")
formals(fun) <- c(unlist(ff), alist(id=))
fun
}
which one may use on a function foo,
foo = function(x){
x
}
sugar(foo) # results in the extended closure,
function (x, id)
{
x
}
Its limitation (other
2024 Feb 18
1
Capturing Function Arguments
? Sat, 17 Feb 2024 11:15:43 -0700
"Reed A. Cartwright" <racartwright at gmail.com> ?????:
> I'm wrapping a function in R and I want to record all the arguments
> passed to it, including default values and missing values.
This is hard if not impossible to implement for the general case
because the default arguments are evaluated in the environment of the
function as it
2016 Oct 19
0
How to assign NULL value to pairlist element while keeping it a pairlist?
On Wed, 19 Oct 2016, Henrik Bengtsson wrote:
> On Sat, Oct 15, 2016 at 2:00 AM, Martin Maechler
> <maechler at stat.math.ethz.ch> wrote:
>>>>>>> Michael Lawrence <lawrence.michael at gene.com>
>>>>>>> on Wed, 12 Oct 2016 15:21:13 -0700 writes:
>>
>> > Thanks, this was what I expected. There is a desire to
>>
2002 May 24
0
2.2.4 and XP Pro
I have Samba 2.2.4 running on RedHat 7.3 and I am trying to connect a
Win XP Pro laptop to it. I installed the latest (as of today) registry
fix on the laptop, but when I browse to the samba server in network
neighborhood, I get the message:
\\Localhost
<file:///\\Localhost%20is%20not%20accessible.%20You%20might%20not%20have
2013 Feb 04
2
Modifying a function programmatically
Dear list
# I have a function
ff <- function(a,b=2,c=4){a+b+c}
# which I programmatically want to modify to a more specialized function in which a is replaced by 1
ff1 <- function(b=2,c=4){1+b+c}
# I do as follows:
vals <- list(a=1)
(expr1 <- as.expression(body(ff)))
expression({
a + b + c
})
(expr2 <- do.call("substitute", list(expr1[[1]], vals)))
{
1 +
2012 Oct 04
2
How to build a list with missing values? What is missing, anyway?
This is tangentially related to Hadley's question.
Suppose I'm building a function programmatically; I have assembled an
expression for the body and I know the names of the arguments it wants
to take.
Suppose I have some convenience function such that writing
make_function(alist(a=, b=), quote(a+b), environment())
is equivalent to writing
function(a,b) a+b
So how do I make the
2007 Aug 22
2
Evaluating f(x(2,3)) on a function f<- function(a,b){a+b}
Dear list
I have a function and a vector, say
f <- function(a,b){a+b}
x <- c(2,3)
I want to "evaluate f on x" in the sense of computing f(x[1],x[2]). I would like it to be so that I can write f(x). (I know I can write a wrapper function g <- function(x){f(x[1],x[2])}, but this is not really what I am looking for). Is there a general way doing this (programmatically)?
2011 Dec 05
2
class extension and documentation
I've added a "backsolve" method to the bdsmatrix library.
Per the Extending manual section 7.1 I've also added the following 3
lines along with my setMethod definitions for 2 classes.
backsolve <- function(r, ...) UseMethod("backsolve")
backsolve.default <- base:::backsolve
formals(backsolve.default) <- c(formals(backsolve.default), alist(...
= ))
I've
2009 Apr 17
1
cast function in package reshape
Hello R useRs,
I have a function which returns a list of functions :
freq1 <- function(x) {
lev <- unique(x[!is.na(x)])
nlev <- length(lev)
args <- alist(x=)
if (nlev == 1) {
body <- c("{", "sum(!is.na(x))", "}")
f <- function() {}
formals(f) <- as.pairlist(args)
body(f) <- parse(text = body)
namef <-
2004 Jan 15
3
Extracting multiple elements from a list
For a long time I've wanted a way to conveniently extract multiple elements
from a list, which [[ doesn't allow. Can anyone suggest an efficient
function to do this? Wouldn't it be a sensible addition to R?
For example,
alist <- list()
alist[[1]] <- list()
alist[[1]]$name <- "first"
alist[[1]]$vec <- 1:4
alist[[2]] <- list()
alist[[2]]$name <-
2003 Aug 20
0
end-of-loop-timeout problem and submit-bug-report output (resending) (PR#3841)
(Hi,
I tried sending this to ess-bugs, but got it bounced back: "user unknown".
Hope this isn't too off-topic for ess-help.
Scot)
I'm using Xemacs 21.4, ess 5.1.24, on Windows 98 SE, with John Fox's
configuration files:
(http://socserv.mcmaster.ca/jfox/Books/Companion/ESS/index.html)
and am getting the end-of-loop-timeout warning message I've seen reported
to
2016 Oct 19
2
How to assign NULL value to pairlist element while keeping it a pairlist?
On Sat, Oct 15, 2016 at 2:00 AM, Martin Maechler
<maechler at stat.math.ethz.ch> wrote:
>>>>>> Michael Lawrence <lawrence.michael at gene.com>
>>>>>> on Wed, 12 Oct 2016 15:21:13 -0700 writes:
>
> > Thanks, this was what I expected. There is a desire to
> > eliminate the usage of pairlist from user code, which
> >
2003 Nov 13
1
Can't get Sweave syntax highlighting with Emacs
I can't get Emacs to automatically do syntax highlighting of
Sweave files. I have followed Friedrich's suggestion for code
to insert into my .emacs file. The complete section from my .emacs
file is given below. When I load a *.Snw file, font is white until I press
M-x, then the first code and document chunks get highlighted, but not
the rest of the file. Latex and Noweb menus are
2018 Oct 06
1
Warning when calling formals() for `[`.
Hi,
Thanks for the note. How would explain the following snippet taken from
`formals` doc page (the code comment is also from that doc) ?
## formals returns NULL for primitive functions. Use it in combination with
## args for this case.
is.primitive(`+`)
formals(`+`)
formals(args(`+`))
Le sam. 6 oct. 2018 ? 13:42, Rui Barradas <ruipbarradas at sapo.pt> a ?crit :