Displaying 20 results from an estimated 7000 matches similar to: "setMethod("Logic", ...)"
2006 Aug 30
1
setMethod() and log()
Hi
I am having difficulty with setMethod(). I have a "brob" class of
objects whose
representation has two slots: "x" and "positive". Slot "x" (double)
holds the log
of a number and slot "positive" (logical) its sign. The idea is
that large numbers
can be handled.
I'm trying to implement a log() method using an analogue of the
2006 Sep 15
1
setMethod() woes
Hello everybody
R version 2.4.0 alpha (2006-09-15 r39323), MacOSX 10.4.7
Next S4 problem.
I have "brob" objects that are large real numbers, and now I want "glub"
numbers that are to be a pair of glubs that represent complex numbers.
I want to define binary operator "+" so that if either the left or right
argument are glubs, it uses .ArithGlub.
If either
2006 Sep 04
1
setMethod("Summary")
Hi everyone and thanks for being patient. I've used "!.foo"() et
seq pro tem.
Next problem: how to define "Summary" methods for brobs.
?max says
'max' and 'min' are generic functions: methods can be defined for
them individually or via the 'Summary' group generic. For this to
work properly, the arguments '...' should be
2006 Oct 31
1
setReplaceMethod
Hi
If x <- 1:10 then x[5] <- 1i will promote
x to be a complex vector.
Suppose I have an S4 class "brob", and have functions
is.brob(), as.brob(), as.numeric() and so forth (minimal self-contained
code below).
If x is numeric (1:10, say) and y is a brob, what
is the best way to make
x[5] <- y
promote x to a brob in the same way as the complex example?
Or is
2006 Sep 12
1
package.skeleton() in R-2.4.1
Hi
R version 2.4.0 alpha (2006-09-06 r39158)
MacOSX 10.4.7
There was a thread some time ago as to whether the structure created by
package.skeleton() would pass R CMD check.
I have an example where package.skeleton() gives an R file that gives an
error when sourced.
If I type
setClass("brob",
representation = representation
2007 Aug 30
7
Behaviour of very large numbers
Dear all,
I am struggling to understand this.
What happens when you raise a negative value to a power and the result
is a very large number?
B
[1] 47.73092
> -51^B
[1] -3.190824e+81
# seems fine
# now this:
> x <- seq(-51,-49,length=100)
> x^B
[1] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN <snip>
> is.numeric(x^B)
[1] TRUE
> is.real(x^B)
[1]
2005 Jul 29
1
octonions
Hi
I thought it would be fun to develop R functionality for
the octonions (there is already some work on quaternions).
The octonions are an 8 dimensional algebra over the reals, so an
octonion
may nicely be represented as a real vector of length 8. Applications
are many and varied, mostly quantum mechanics.
I would like to develop some R functionality in this area.
My first problem is how
2008 May 07
1
optional setValidity()
Hi
Suppose I have an S4 class "foo" and a validity checking
function ".checkfoo()":
setClass("foo", representation=representation("numeric"))
setValidity("foo" , .checkfoo)
is fine; in my application, .checkfoo() verifies that a bunch
of necessary conditions are met.
But .checkfoo() is very time consuming and I want
to give users the option
2005 Jan 07
1
Visualizing complex analytic functions using domain coloring
Hi
has anyone coded up domain colouring for visualizing complex analytic
functions
(such as elliptic functions)?
[
the idea is to depict a complex function f(z) using a filled.contour()
variant
in which the hue is given by Arg(f(z)), and the saturation by Mod(f(z)).
]
--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
European Way, Southampton SO14 3ZH, UK
tel
2006 Sep 13
3
functions and strings
Hi
If
string <- "xyz"
f <- function(x){1 + sin(cos(x)) + exp(x^2)}
How do I manipulate "string" and f() to give the string
"1 + sin(cos(xyz)) + exp(xyz^2)"
?
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743
2005 Nov 17
3
changing figure size in Sweave
Hi
In Sweave, how does one change the size of the plots?
I tried using a hook:
<<echo=FALSE, print=FALSE, fig=TRUE>>=
options(SweaveHooks=list(fig=function() ps.options(width=1)))
library(graphics)
pairs(iris)
@
but this didn't change the size of the figure. How to make the
figures a
different size?
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre,
2006 Feb 22
3
elements that appear only once
Hi.
I have a factor and I want to extract just those elements that appear
exactly once.
How to do this?
Toy example follows.
> a <- as.factor(c(rep("oak",5) ,rep("ash",1),rep("elm",1),rep
("beech",4)))
> a
[1] oak oak oak oak oak ash elm beech beech beech beech
Levels: ash beech elm oak
> table(a)
a
ash beech elm oak
2007 Mar 19
3
character to numeric conversion
Hi.
Is there a straightforward way to convert a character string
containing comma-delimited
numbers to a numeric vector?
In my application, I use
system(executable.string, intern=TRUE)
which returns a string like
"[0.E-38, 2.096751179214927596171268230,
3.678944959657480671183123052, 4.976528845643001020345216157,
6.072390165503099343887569007, 7.007958550337542210168866070,
2006 Feb 28
2
lines() and recycled colours
Hi
?lines says
For 'type = "h"', 'col' can be a vector and will be recycled as
needed.
Why doesn't lines() recycle colours for other types?
If I type
> plot(0:1,0:1,type="n")
> lines(runif(11),runif(11),col=c("red","green"))
>
then all ten lines are red, with no warning given. Is there a reason
why
2008 Mar 26
5
S4 slot with NA default
Hi
How do I specify an S4 class with a slot that is potentially numeric,
but NA
by default? I want the slot to be NA until I calculate its value
(an expensive operation, not needed for all applications). When
its value is
known, I will create a new object with the correct value inserted in
the slot.
I want "NA" to signify "not known".
My attempt fails because
2006 Jul 27
4
inserting rows into a matrix
Hi
I have a little vector function that takes a vector A of strictly
positive integers
and outputs a matrix M each of whose columns is the vector, modified in
a complicated combinatorical way.
Now I want to generalize the function so that A can include zeroes.
Given A,
I want to strip out the zeroes, pass it to my function, and pad M
with rows at positions corresponding to the zeroes
2006 Jul 25
2
pari/gp interface
Hi
I'm developing an R package that
needs to execute some code written in pari/gp.
I've used this before from an R package (elliptic) but the interface
is very
basic: the R function creates a string such as the following:
string <- echo ' ellwp ([ 2+0*I , 0+2*I ], 1+0*I )' | gp -q
And then
system(string)
returns the output from gp which then needs to be text processed
2008 Jan 14
2
as.function()
Hi
[this after some considerable thought as to R-help vs R-devel]
I want to write a (S3) method for as.function();
toy example follows.
Given a matrix "a", I need to evaluate trace(ax) as a function of
(matrix) "x".
Here's a trace function:
tr <- function (a) {
i <- seq_len(nrow(a))
return(sum(a[cbind(i, i)]))
}
How do I accomplish the following:
2005 Jun 13
3
extracting components of a list
Hi
how do I extract those components of a list that satisfy a certain
requirement? If
jj <- list(list(a=1,b=4:7),list(a=5,b=3:6),list(a=10,b=4:5))
I want just the components of jj that have b[1] ==4 which in this case
would be the first and
third of jj, viz list (jj[[1]],jj[[3]]).
How to do this efficiently?
My only idea was to loop through jj, and set unwanted components to
NULL,
2007 Jan 16
5
"[[" gotcha
The following gotcha caught me off-guard just now.
I have two matrices, a and b:
a <- matrix(1,3,3)
b <- matrix(1,1,1)
(note that both "a" and "b" are matrices).
I want them in a list:
> B <- NULL
> B[[1]] <- a
> B[[2]] <- b
> B
[[1]]
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 1 1 1
[3,] 1 1 1
[[2]]
[,1]
[1,] 1