Displaying 20 results from an estimated 8000 matches similar to: "seq.Date requires by"
2005 Mar 08
4
how modify object in parent.env
Hi,
Is it possible to modify an object in the parent.env (as opposed to
re-bind)? Here is what I tried:
> x = 1:3
# try to modify the first element of x from within a new environment
> local(get("x", parent.env(environment()))[1] <- NA)
Error in eval(expr, envir, enclos) : Target of assignment expands to
non-language object
# On the other hand retrieval works just fine
>
2003 Sep 03
3
read.table: check.names arg - feature request
Hi,
I thought it would be convenient if the check.names argument to read.table, which currently can only be TRUE/FALSE, could take a function value as well. If the function is supplied it should be used instead of the default make.names.
Here is an example where it can come in handy. I tend to keep my data in coma-separated files with a header line. The header line is prefixed with a comment
2004 May 01
5
skip lines on a connection
Hi,
I am looking for an efficient way of skipping big chunks of lines on a
connection (not necessarily at the beginning of the file). One way is to
use read lines, e.g. readLines(1e6), but a) this incurs the overhead of
construction of the return char vector and b) has a (fairly remote)
potential to blow up the memory.
Another way would be to use scan(), e.g.
scan(con, skip=1e6, nmax=0)
2004 Jun 08
5
fast mkChar
Hi,
To speed up reading of large (few million lines) CSV files I am writing
custom read functions (in C). By timing various approaches I figured out
that one of the bottlenecks in reading character fields is the mkChar()
function which on each call incurs a lot of garbage-collection-related
overhead.
I wonder if there is a "vectorized" version of mkChar, say mkChar2(char
**, int
2004 Nov 10
3
recursive default argument reference
Hi,
It seems that a formal function argument can not default to an "outer"
variable of the same name:
> x <- "foo"
> ff <- function(x=x) x
> ff()
Error in ff() : recursive default argument reference
>
Is this intentional? Why?
I use R-1.9.1.
Thanks,
Vadim
2005 May 07
4
how to add method to .Primitive function
Hi,
I tried to write the dim method for the list class, but R doesn't seem
to dispatch to it:
> dim.list = function(x) c(length(x[[1]]), length(x))
> dim(list(1))
NULL
> dim.list(list(1))
[1] 1 1
What is the correct way of registering dim.list with .Primitive("dim")?
Thanks,
Vadim
[[alternative HTML version deleted]]
2004 Mar 02
3
error() and C++ destructors
Hi,
I am writing C++ functions that are to be called via .Call() interface.
I'd been using error() (from R.h) to return to R if there is an error,
but then I realized that this might be not safe as supposedly error()
doesn't throw an exception and therefore some destructors do not get
called and some memory may leak. Here is a simple example
extern "C" void foo() {
string
2004 Jun 30
2
Slow IO: was [R] naive question
I believe IO in R is slow because of the way it is implemented, not
because it has to do some extra work for the user.
I compared scan() with 'what' argument set (which is, AFAIK, is the
fastest way to read a CSV file) to an equivalent C code. It turned out
to be 20 - 50 times slower.
I can see at least two main reasons why R's IO is so slow (I didn't
profile this though):
A) it
2004 Nov 26
2
Lightweight data frame class
Hi,
As far as I can tell data.frame class adds two features to those of
lists:
* matrix structure via [,] and [,]<- operators (well, I know these are
actually "["(i, j, ...), not "[,]").
* row names attribute.
It seems that the overhead of the support for the row names, both
computational and RAM-wise, is rather non-trivial. I frequently
subscript from a data.frame,
2004 Nov 19
3
how to get to interesting part of pattern match
Hi,
I am looking for a way to extract an "interesting" part of the match to
a regular expression. For example the pattern "[./](*.)" matches a
substring that begins with either "." or "/" followed by anything. I am
interested in this "anything" w/o the "." or "/" prefix. If say I match
the pattern against "abc/foo" I
2004 Sep 24
1
algorithm reference for sample()
Hi,
Don't know if it belongs to r-devel or r-help, but since I am planning
to alter some of R's internal code I am sending it here.
The existing implementation of the sample() function, when the optional
'prob' argument is given, is quite inefficient. The complexity is
O(sampleSize * universeSize), see ProbSampleReplace() and
ProbSampleNoReplace() in random.c. This makes the
2004 Apr 23
3
time zones in POSIXt
Hi,
I have two data sources. One records time in PST time zone, the other in
GMT. I want to compute the difference between the two, but don't see
how. Here is an example where I compute time difference between
identical times each (meant to be) relative to its time zone.
> as.POSIXlt("2000-05-10 10:15:00", "PST") - as.POSIXlt("2000-05-10
10:15:00",
2005 Jun 10
1
Redirect console to file
Hi,
Is it possible to redirect the staff that normally goes to the R console
window into a file. sink() does this for sdterr and stdout. But I need
something that redirects "everything" that appear in the console window
(including the top-level commands).
I want to achieve the same effect as that of the following command under
sh:
R < foo.R &> foo.Rt
only I want the
2005 May 08
3
Light-weight data.frame class: was: how to add method to .Primitive function
Hi,
Encouraged by a tip from Simon Urbanek I tried to use the S3 machinery
to write a faster version of the data.frame class.
This quickly hits a snag: the "[.default"(x, i) for some reason cares
about the dimensionality of x.
In the end there is a full transcript of my R session. It includes the
motivation for writing the class and the problems I have encountered.
As a result I see
2004 Mar 06
2
.Call: is new attribute of protected object auto-protected
Hi,
I have an SEXP obj in a C function called via .Call(). The obj is
protected (in fact it is an argument to .Call and therefore
automatically protected). If I set an attribute of obj does the
attribute become protected too? Here is an example
SEXP foo(SEXP obj) {
SET_NAMES(obj, NEW_CHARACTER(3)); /* are names protected or not? */
...
}
Thanks,
Vadim
[[alternative HTML version
2004 Aug 20
1
gcc optimization flag when building R
Hi,
I am building R on RH Linux 7.3 and I noticed that ./configure does not
set the optimization flag, -O or -O2, for gcc, but does set for g++ and
g77. Why is that? Should I try to set it manually, if yes how?
Thanks,
Vadim
P.S. This is the bottom portion of the ./configure run
R is now configured for i686-pc-linux-gnu
Source directory: .
Installation directory:
2005 Mar 16
1
function-like macros undefined
Hi,
Somehow function-like macros from Rinternals.h are not defined when I
include the file.
foo.c
##################
#include <R.h>
#include <Rinternals.h>
#ifndef NILSXP
#error("NILSXP")
#endif
#ifndef INTEGER
#error("INTEGER")
#endif
###################
When compiled:
vor/src% gcc -I/usr/local/lib/R/include -g -O2 -c foo.c -o foo.o
foo.c:11:2: #error
2005 May 06
1
distance between distributions
Hi,
This is more of a general stat question. I am looking for a easily
computable measure of a distance between two empirical distributions.
Say I have two samples x and y drawn from X and Y. I want to compute a
statistics rho(x,y) which is zero if X = Y and grows as X and Y become
less similar.
Kullback-Leibler distance is the most "official" choice, however it
needs estimation of
2004 Aug 20
1
make check failed with a minor error
Hi,
I am building R off the source file "The latest release (2004-06-21):
R-1.9.1.tgz <http://cran.stat.ucla.edu/src/base/R-1.9.1.tgz> " on RH
Linux 7.3. After the build the "make check" failed with an error which I
judge to be minor, but would like to hear from the experts in the field.
Is it harmeless? Can it indicate some problem with my computer setup
(not R)?
2005 Apr 03
1
Error: NAs are not allowed in subscripted assignments: change from R.1.9
Hi,
There seems to be a change in 2.0.1 in the workings of subscript
assignments with missing values.
# This is R.2.0.1
# assignment w/ missing index doesn't work when right-hand-side is a
matrix. It did work in 1.9.1
> x = matrix(1, 2, 2); x[c(1,NA),] = x
Error: NAs are not allowed in subscripted assignments
# it does work for a vector
> x = matrix(1, 2, 2); x[c(1,NA),] = 1
Is this