Displaying 20 results from an estimated 10000 matches similar to: "Definition of [["
2009 Mar 23
2
dput(as.list(function...)...) bug
Tested in R 2.8.1 Windows
> ff <- formals(function(x)1)
> ff1 <- as.list(function(x)1)[1]
# ff1 acts the same as ff in the examples below, but is a list rather
than a pairlist
> dput( ff , control=c("warnIncomplete"))
list(x = )
This string is not parsable, but dput does not give a warning as specified.
> dput( ff ,
2014 May 27
1
dput line width
Is there some way to control the line width that dput uses?
options(width=...) does not affect dput.
For example, currently
> dput(1:30*2)
c(2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, *line break
here*
34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60)
but on a wider display, I'd like to have no line break.
Tested on R version 3.1.0 (2014-04-10)
2009 Jun 11
2
Tables without names
A table without names displays like a vector:
> unname(table(2:3))
[1] 1 1 1
and preserves the table class (as with unname in general):
> dput(unname(table(2:3)))
structure(c(1L, 1L), .Dim = 2L, class = "table")
Does that make sense? R is not consistent in its treatment of such unname'd
tables:
In plot, they are considered erroneous input:
>
2009 Jun 03
1
Vectorize fails for function with ... arglist
Vectorize is defined to return a function that acts as if 'mapply' was
called.
So we have:
> mapply(dput,1:2) # mapply form
1L # calls dput on each element of 1:2
2L
[1] 1 2
> Vectorize(dput)(1:2) # Vectorize form
1L # same behavior
2L
[1] 1 2
Same thing with a named argument:
>
2014 May 27
1
Pretty-printer for R data
Is there a pretty-printer for R data (and code for that matter), similar to
Lisp's prettyprint/grind? I've looked in CRAN, and couldn't find anything.
For example, I'd like to have:
prettyprint(list(a=1:20*2, b=list(data.frame(q = c(2,1,3),
r = c(3,1,2), s = c(1,3,2)), as.POSIXct("2014-02-03")))
* =>*
list(a = c(2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22,
2009 Jan 25
3
Defining an iterator
Inspired by Rudolf Biczok's query of Fri, Jan 23, 2009 at 1:25 AM, I
tried to implement iteration in a generic way using S4. (Though I am
admittedly still struggling with learning S4.)
> setClass("foo",representation(bar="list"))
[1] "foo"
> x<-new("foo",bar=list(1,2,3))
Given this, I would not expect for(i in x)... to work, since R has no
way
2009 Apr 13
2
Using trace
I would like to trace functions, displaying their arguments and return
value, but I haven't been able to figure out how to do this with the
'trace' function.
After some thrashing, I got as far as this:
fact <- function(x) if(x<1) 1 else x*fact(x-1)
tracefnc <- function() dput(as.list(parent.frame()), #
parent.frame() holds arg list
2009 Apr 13
2
Using trace
I would like to trace functions, displaying their arguments and return
value, but I haven't been able to figure out how to do this with the
'trace' function.
After some thrashing, I got as far as this:
fact <- function(x) if(x<1) 1 else x*fact(x-1)
tracefnc <- function() dput(as.list(parent.frame()), #
parent.frame() holds arg list
2009 Jun 03
1
Print bug for matrix(list(NA_complex_, ...))
In R 2.8.0 on Windows (tested both under ESS and under R Console in case
there was an I/O issue)
There is a bug in printing val <- matrix(list(NA_complex_,NA_complex_),1).
> dput(val)
structure(list(NA_complex_, NA_complex_), .Dim = 1:2)
> print(val)
[,1]
[1,]
[,2]
[1,]
Note that a large number of spaces are printed instead of NA. Compare the
unproblematic real case:
2009 Apr 01
2
Definition of = vs. <-
NOTA BENE: This email is about `=`, the assignment operator (e.g. {a=1}
which is equivalent to { `=`(a,1) } ), not `=` the named-argument syntax
(e.g. f(a=1), which is equivalent to
eval(structure(quote(f(1)),names=c('','a'))).
As far as I can tell from the documentation, assignment with = is precisely
equivalent to assignment with <-. Yet they call different primitives:
>
2009 Apr 01
2
Definition of = vs. <-
NOTA BENE: This email is about `=`, the assignment operator (e.g. {a=1}
which is equivalent to { `=`(a,1) } ), not `=` the named-argument syntax
(e.g. f(a=1), which is equivalent to
eval(structure(quote(f(1)),names=c('','a'))).
As far as I can tell from the documentation, assignment with = is precisely
equivalent to assignment with <-. Yet they call different primitives:
>
2009 Mar 31
1
as.data.frame peculiarities
The documentation of as.data.frame is not explicit about how it generates
column names for the simple vector case, but it seems to use the character
form of the quoted argument, e.g.
names(as.data.frame(1:3))
[1] "1:3"
But there is a strange case:
names(as.data.frame(c("a")))
[1] "if (stringsAsFactors) factor(x) else x"
I feel fairly comfortable calling this a
2008 Dec 08
4
R and Scheme
I've read in many places that R semantics are based on Scheme semantics. As
a long-time Lisp user and implementor, I've tried to make this more precise,
and this is what I've found so far. I've excluded trivial things that
aren't basic semantic issues: support for arbitrary-precision integers;
subscripting; general style; etc. I would appreciate corrections or
additions from
2009 Dec 18
2
Vectorized switch
What is the 'idiomatic' way of writing a vectorized switch statement?
That is, I would like to write, e.g.,
vswitch( c('a','x','b','a'),
a= 1:4,
b=11:14,
100 )
=> c(1, 100, 13, 4 )
equivalent to
ifelse( c('a','x','b','a') ==
2008 Nov 29
2
Using grep() to subset lines of text
I have two vectors, a and b. b is a text file. I want to find in b those
elements of a which occur at the beginning of the line in b. I have the
following code, but it only returns a value for the first value in a, but I
want both. Any ideas please.
a = c(2,3)
b = NULL
b[1] = "aaa 2 aaa"
b[2] = "2 aaa"
b[3] = "3 aaa"
b[4] = "aaa 3 aaa"
2009 Feb 17
2
cumsum vs. sum
I recently traced a bug of mine to the fact that cumsum(s)[length(s)]
is not always exactly equal to sum(s).
For example,
x<-1/(12:14)
sum(x) - cumsum(x)[3] => 2.8e-17
Floating-point addition is of course not exact, and in particular is
not associative, so there are various possible reasons for this.
Perhaps sum uses clever summing tricks to get more accurate results?
In some
2009 Jul 29
3
Object equality for S4 objects
To test two environments for object equality (Lisp EQ), I can use 'identity':
> e1 <- environment(local(function()x))
> e2 <- environment(local(function()x))
> identical(e1,e2) # compares object identity
[1] FALSE
> identical(as.list(e1),as.list(e2)) # compares values as name->value mapping
[1] TRUE # (is there a
2009 Mar 09
3
E`<`<rrors in recursive default argument references
Tested in: R version 2.8.1 (2008-12-22) / Windows
Recursive default argument references normally give nice clear errors.
In the first set of examples, you get the error:
Error in ... :
promise already under evaluation: recursive default argument
reference or earlier problems?
(function(a = a) a ) ()
(function(a = a) c(a) ) ()
(function(a = a) a[1] ) ()
(function(a = a)
2009 May 20
2
Class for time of day?
What is the recommended class for time of day (independent of calendar
date)?
And what is the recommended way to get the time of day from a POSIXct
object? (Not a string representation, but a computable representation.)
I have looked in the man page for DateTimeClasses, in the Time Series
Analysis Task View and in Spector's Data Manipulation book but haven't found
these. Clearly I can
2009 Feb 10
1
Variable/function namespaces WAS: Bug in subsetting data frame (PR#13515)
On Tue, Feb 10, 2009 at 10:11 AM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> Stavros Macrakis wrote:
>> On Tue, Feb 10, 2009 at 8:31 AM, Duncan Murdoch <murdoch at stats.uwo.ca>wrote:
>>> The evaluator recognizes the context of usage and will get the
>>> function for a function call....
>> Can you point me to chapter and verse in the language