Re: [R] Printout and saved results

2024-03-25 Thread Jeff Newmiller via R-help
Your desire is not unusual among novices... but it is really not a good idea 
for your function to be making those decisions. Look at how R does things:

The lm function prints nothing... it returns an object containing the result of 
a linear regression. If you happen to call it directly from the R command 
prompt and don't assign it to a variable, then the command interpreter notices 
that return value and prints it. Since the lm object has a dedicated print 
method associated with it, that output looks different than a plain list object 
would... but the fact that it has a special print method (?print.lm) is just 
window dressing unrelated to your request.

The important part is that the lm function doesn't even consider printing 
anything out... it is the code that calls the function that determines whether 
it will get printed. So...

lm( hp ~ disp, data = mtcars )  # printed by command interpreter
z <- lm( hp ~ disp, data = mtcars ) # assignment operator returns the value of 
z to the command processor, but invisibly
( z <- lm( hp ~ disp, data = mtcars ) ) # strips off the invisible marking so 
the value gets printed

Another example:

f <- function() {
  x <- 4
  x  # doesn't print
  invisible( 5 ) # return invisible result
}

f()  # doesn't print 4 because there is no command prompt looking at x alone on 
a line... it is inside f
# command prompt doesn't print 5 because that 5 has been marked as invisible
(f()) # command interpreter prints 5

Leaving it up to the calling code to decide whether to print gives you the 
option of calling your analysis function possibly thousands of times and 
figuring out some slick way to summarize all those runs without thousands of 
printouts that you are not going to wade through anyway and would only slow the 
computer down (printing really does slow the computer down!)


On March 25, 2024 9:00:49 PM PDT, Steven Yen  wrote:
>I just like the subroutine to spit out results (Mean, Std.dev, etc.) and also 
>be able to access the results for further processing, i.e.,
>
>v$Mean
>
>v$Std.dev
>
>On 3/26/2024 11:24 AM, Richard O'Keefe wrote:
>> Not clear what you mean by "saved".
>> If you call a function and the result is printed, the result is
>> remembered for a wee while in
>> the variable .Last.value, so you can do
>>> function.with.interesting.result(...)
>>> retained.interesting.result <- .Last.value
>> or even
>>> .Last.value -> retained.interesting.result
>> If you know before you start writing the expression that you want to
>> save the value,
>> you can wrap the assignment in parentheses, making it an expression:
>> 
>>> (retained.interesting.result <- function.with.interesting.result(..))
>> 
>> On Tue, 26 Mar 2024 at 15:03, Steven Yen  wrote:
>>> How can I have both printout and saved results at the same time.
>>> 
>>> The subroutine first return "out" and the printout gets printed, but not
>>> saved.
>>> 
>>> I then run the "invisible" line. Results got saved and accessible but no
>>> printout.
>>> 
>>> How can I have both printout and also have the results saved? Thank you!
>>> 
>>>   > dstat4 <- function(data,digits=3){
>>> +   Mean<- apply(data,2,mean,na.rm=TRUE)
>>> +   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
>>> +   Min <- apply(data,2,min,na.rm=TRUE)
>>> +   Max <- apply(data,2,max,na.rm=TRUE)
>>> +   Obs <- dim(data)[1]
>>> +   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
>>> +   out
>>> + # invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
>>> + }
>>>   > x1<-rnorm(n=5,mean=5, sd=1)
>>>   > x2<-rnorm(n=5,mean=10,sd=2)
>>>   > w<-rnorm(n=5,mean=2,sd=0.3)
>>>   > mydata<-data.frame(cbind(x1,x2))
>>>   > v<-dstat4(mydata); v
>>>Mean Std.dev   MinMax Obs
>>> x1  5.000   0.922 3.900  6.282   5
>>> x2 10.769   1.713 9.209 13.346   5
>>>   > v$Mean
>>> Error in v$Mean : $ operator is invalid for atomic vectors
>>>   > dstat4 <- function(data,digits=3){
>>> +   Mean<- apply(data,2,mean,na.rm=TRUE)
>>> +   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
>>> +   Min <- apply(data,2,min,na.rm=TRUE)
>>> +   Max <- apply(data,2,max,na.rm=TRUE)
>>> +   Obs <- dim(data)[1]
>>> +   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
>>> + # out
>>> +   invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
>>> + }
>>> 
>>>   > v<-dstat4(mydata)
>>>   > v$Mean
>>> x1   x2
>>> 4.233051 9.564454
>>> 
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible 

Re: [R] Printout and saved results

2024-03-25 Thread Steven Yen
I just like the subroutine to spit out results (Mean, Std.dev, etc.) and 
also be able to access the results for further processing, i.e.,


v$Mean

v$Std.dev

On 3/26/2024 11:24 AM, Richard O'Keefe wrote:

Not clear what you mean by "saved".
If you call a function and the result is printed, the result is
remembered for a wee while in
the variable .Last.value, so you can do

function.with.interesting.result(...)
retained.interesting.result <- .Last.value

or even

.Last.value -> retained.interesting.result

If you know before you start writing the expression that you want to
save the value,
you can wrap the assignment in parentheses, making it an expression:


(retained.interesting.result <- function.with.interesting.result(..))


On Tue, 26 Mar 2024 at 15:03, Steven Yen  wrote:

How can I have both printout and saved results at the same time.

The subroutine first return "out" and the printout gets printed, but not
saved.

I then run the "invisible" line. Results got saved and accessible but no
printout.

How can I have both printout and also have the results saved? Thank you!

  > dstat4 <- function(data,digits=3){
+   Mean<- apply(data,2,mean,na.rm=TRUE)
+   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
+   Min <- apply(data,2,min,na.rm=TRUE)
+   Max <- apply(data,2,max,na.rm=TRUE)
+   Obs <- dim(data)[1]
+   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
+   out
+ # invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
+ }
  > x1<-rnorm(n=5,mean=5, sd=1)
  > x2<-rnorm(n=5,mean=10,sd=2)
  > w<-rnorm(n=5,mean=2,sd=0.3)
  > mydata<-data.frame(cbind(x1,x2))
  > v<-dstat4(mydata); v
   Mean Std.dev   MinMax Obs
x1  5.000   0.922 3.900  6.282   5
x2 10.769   1.713 9.209 13.346   5
  > v$Mean
Error in v$Mean : $ operator is invalid for atomic vectors
  > dstat4 <- function(data,digits=3){
+   Mean<- apply(data,2,mean,na.rm=TRUE)
+   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
+   Min <- apply(data,2,min,na.rm=TRUE)
+   Max <- apply(data,2,max,na.rm=TRUE)
+   Obs <- dim(data)[1]
+   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
+ # out
+   invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
+ }

  > v<-dstat4(mydata)
  > v$Mean
x1   x2
4.233051 9.564454

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [External] Printout and saved results

2024-03-25 Thread Richard M. Heiberger
dstat4 <- function(data) {
  Mean<- apply(data, 2, mean, na.rm=TRUE)
  Std.dev <- apply(data, 2, sd,  na.rm=TRUE)
  Min <- apply(data, 2, min, na.rm=TRUE)
  Max <- apply(data, 2, max, na.rm=TRUE)
  Obs <- dim(data)[1]
  data.frame(Mean, Std.dev, Min, Max, Obs)
}

## don't round inside a function.
## rounding is for printing, not for calculating.
## use a space after a comma
## use a space on both sides of assignment <-

## I made the result a data.frame to allow $ selection to work.

x1 <- rnorm(n=5, mean=5, sd=1)
x2 <- rnorm(n=5, mean=10, sd=2)
w <- rnorm(n=5, mean=2, sd=0.3)
mydata <- data.frame(x1, x2, w)

dstat4(mydata)

round(v <- dstat4(mydata), digits=3)

v

v$Mean

round(v$Mean, 3)


> On Mar 25, 2024, at 22:02, Steven Yen  wrote:
>
> How can I have both printout and saved results at the same time.
>
> The subroutine first return "out" and the printout gets printed, but not 
> saved.
>
> I then run the "invisible" line. Results got saved and accessible but no 
> printout.
>
> How can I have both printout and also have the results saved? Thank you!
>
> > dstat4 <- function(data,digits=3){
> +   Mean<- apply(data,2,mean,na.rm=TRUE)
> +   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
> +   Min <- apply(data,2,min,na.rm=TRUE)
> +   Max <- apply(data,2,max,na.rm=TRUE)
> +   Obs <- dim(data)[1]
> +   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
> +   out
> + # invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
> + }
> > x1<-rnorm(n=5,mean=5, sd=1)
> > x2<-rnorm(n=5,mean=10,sd=2)
> > w<-rnorm(n=5,mean=2,sd=0.3)
> > mydata<-data.frame(cbind(x1,x2))
> > v<-dstat4(mydata); v
>  Mean Std.dev   MinMax Obs
> x1  5.000   0.922 3.900  6.282   5
> x2 10.769   1.713 9.209 13.346   5
> > v$Mean
> Error in v$Mean : $ operator is invalid for atomic vectors
> > dstat4 <- function(data,digits=3){
> +   Mean<- apply(data,2,mean,na.rm=TRUE)
> +   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
> +   Min <- apply(data,2,min,na.rm=TRUE)
> +   Max <- apply(data,2,max,na.rm=TRUE)
> +   Obs <- dim(data)[1]
> +   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
> + # out
> +   invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
> + }
>
> > v<-dstat4(mydata)
> > v$Mean
>   x1   x2
> 4.233051 9.564454
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.r-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Printout and saved results

2024-03-25 Thread Richard O'Keefe
Not clear what you mean by "saved".
If you call a function and the result is printed, the result is
remembered for a wee while in
the variable .Last.value, so you can do
> function.with.interesting.result(...)
> retained.interesting.result <- .Last.value
or even
> .Last.value -> retained.interesting.result

If you know before you start writing the expression that you want to
save the value,
you can wrap the assignment in parentheses, making it an expression:

> (retained.interesting.result <- function.with.interesting.result(..))


On Tue, 26 Mar 2024 at 15:03, Steven Yen  wrote:
>
> How can I have both printout and saved results at the same time.
>
> The subroutine first return "out" and the printout gets printed, but not
> saved.
>
> I then run the "invisible" line. Results got saved and accessible but no
> printout.
>
> How can I have both printout and also have the results saved? Thank you!
>
>  > dstat4 <- function(data,digits=3){
> +   Mean<- apply(data,2,mean,na.rm=TRUE)
> +   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
> +   Min <- apply(data,2,min,na.rm=TRUE)
> +   Max <- apply(data,2,max,na.rm=TRUE)
> +   Obs <- dim(data)[1]
> +   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
> +   out
> + # invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
> + }
>  > x1<-rnorm(n=5,mean=5, sd=1)
>  > x2<-rnorm(n=5,mean=10,sd=2)
>  > w<-rnorm(n=5,mean=2,sd=0.3)
>  > mydata<-data.frame(cbind(x1,x2))
>  > v<-dstat4(mydata); v
>   Mean Std.dev   MinMax Obs
> x1  5.000   0.922 3.900  6.282   5
> x2 10.769   1.713 9.209 13.346   5
>  > v$Mean
> Error in v$Mean : $ operator is invalid for atomic vectors
>  > dstat4 <- function(data,digits=3){
> +   Mean<- apply(data,2,mean,na.rm=TRUE)
> +   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
> +   Min <- apply(data,2,min,na.rm=TRUE)
> +   Max <- apply(data,2,max,na.rm=TRUE)
> +   Obs <- dim(data)[1]
> +   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
> + # out
> +   invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
> + }
>
>  > v<-dstat4(mydata)
>  > v$Mean
>x1   x2
> 4.233051 9.564454
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Printout and saved results

2024-03-25 Thread Steven Yen

How can I have both printout and saved results at the same time.

The subroutine first return "out" and the printout gets printed, but not 
saved.


I then run the "invisible" line. Results got saved and accessible but no 
printout.


How can I have both printout and also have the results saved? Thank you!

> dstat4 <- function(data,digits=3){
+   Mean    <- apply(data,2,mean,na.rm=TRUE)
+   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
+   Min <- apply(data,2,min,na.rm=TRUE)
+   Max <- apply(data,2,max,na.rm=TRUE)
+   Obs <- dim(data)[1]
+   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
+   out
+ # invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
+ }
> x1<-rnorm(n=5,mean=5, sd=1)
> x2<-rnorm(n=5,mean=10,sd=2)
> w<-rnorm(n=5,mean=2,sd=0.3)
> mydata<-data.frame(cbind(x1,x2))
> v<-dstat4(mydata); v
 Mean Std.dev   Min    Max Obs
x1  5.000   0.922 3.900  6.282   5
x2 10.769   1.713 9.209 13.346   5
> v$Mean
Error in v$Mean : $ operator is invalid for atomic vectors
> dstat4 <- function(data,digits=3){
+   Mean    <- apply(data,2,mean,na.rm=TRUE)
+   Std.dev <- apply(data,2,sd,  na.rm=TRUE)
+   Min <- apply(data,2,min,na.rm=TRUE)
+   Max <- apply(data,2,max,na.rm=TRUE)
+   Obs <- dim(data)[1]
+   out <-round(cbind(Mean,Std.dev,Min,Max,Obs),digits)
+ # out
+   invisible(list(Mean=Mean,Std.dev=Std.dev,Min=Min,Max=Max))
+ }

> v<-dstat4(mydata)
> v$Mean
  x1   x2
4.233051 9.564454

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] as.complex()

2024-03-25 Thread Richard O'Keefe
What is your actual problem that you are trying to solve by comparing
imaginary numbers?
The reals are an ordered field.
The complex numbers are a field but cannot support an ordering that is
consistent with
the field (or even ring) axioms.
The imaginary numbers are not a field or even a ring.
To quote Brian Marick's wonderful sticker, "An example would be good about now".


On Tue, 26 Mar 2024 at 03:17, Thomas K  wrote:
>
> Needing a < , > comparison for imaginary numbers
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Double buffering plots on Windows

2024-03-25 Thread Paul Murrell

Hi

I would not describe myself as a heavy user of this stuff (either 
Windows or animation) - are you able to share your examples ?


Paul

On 26/03/24 04:23, Michael L Friendly wrote:

Hi Paul

Is there a concrete working example somewhere that shows how to use 
these to do an animation on Windows (R Gui &/or RStudio) using base R 
plot() and friends?


I have several old examples somewhere that used to work (R < ~ 3), but 
now no longer work as before.





Date: Mon, 25 Mar 2024 10:43:29 +1300

From: Paul Murrell 
mailto:p...@stat.auckland.ac.nz>>


To: "Bickis, Mikelis" 
mailto:bic...@math.usask.ca>>, 
"r-help@r-project.org"


mailto:r-help@r-project.org>>

Subject: Re: [R] Double buffering plots on Windows

Message-ID: 
mailto:b74c68da-a0b2-47dd-b54f-6b318488c...@stat.auckland.ac.nz>>


Content-Type: text/plain; charset="utf-8"; Format="flowed"



Hi



Take a look at dev.hold() and dev.flush()



Paul


---
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University Voice: 416 736-2100 x66249
4700 Keele Street Web: http://www.datavis.ca 
> | @datavisFriendly

Toronto, ONT M3J 1P3 CANADA


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help 

PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html 


and provide commented, minimal, self-contained, reproducible code.


--
Dr Paul Murrell (he/him)
Te Kura Tatauranga | Department of Statistics
Waipapa Taumata Rau | The University of Auckland
Private Bag 92019, Auckland 1142, New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
www.stat.auckland.ac.nz/~paul/

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [ESS] Displaying R plots within an Emacs buffer

2024-03-25 Thread Ramon Diaz-Uriarte via ESS-help


On Mon, 25-March-2024, at 11:21:26, Stephen J Eglen  
wrote:
>> - I works perfectly for me in two different machines (both running
>> Debian and Emacs 29.2.50)
>
> Thanks for confirming.
>
>> - Maybe I am not understanding
>> https://github.com/sje30/ess-unigd#adjust-to-size-of-buffer--dynamically-update
>> , but resize of image (on changing frame and window sizes) happens
>> automagically for me.
>> - The only minor thing is that, for some reason, the svg is shown in
>> Fundamental mode (if I find-file other svgs, they are shown as images
>> directly); I guess it is something with my setup. revert-buffer solves
>> it.
>
> The code that you have currently just uses the default aspect ratio that
> httpgd() provides, i.e. 720x576 pixels.  The images will rescale as you
> change the buffer, but the aspect ratio won't change.

Aha, thanks for the clarification.

>
> I've got it now working locally so that the aspect ratio is the same size
> as the window that you use to view the svg.  This I think is more flexible.

Looking forward to that functionality :-)

Best,

R.

-- 
Ramon Diaz-Uriarte
Department of Biochemistry, Lab B-31
Facultad de Medicina 
Universidad Autónoma de Madrid 
Arzobispo Morcillo, 4
28029 Madrid
Spain

Phone: +34-91-497-2412

Email: rdia...@gmail.com
   r.d...@uam.es
   ramon.d...@iib.uam.es

https://ligarto.org/rdiaz


__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [R] as.complex()

2024-03-25 Thread Ben Bolker
  That's hard to define unambiguously at a mathematical level.  What 
definition did you have in mind?  Can you provide more context?  (Maybe 
you want to compare Mod(x) to Mod(y) ?)


On 2024-03-25 3:23 a.m., Thomas K wrote:

Needing a < , > comparison for imaginary numbers

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Double buffering plots on Windows

2024-03-25 Thread Michael L Friendly
Hi Paul

Is there a concrete working example somewhere that shows how to use these to do 
an animation on Windows (R Gui &/or RStudio) using base R plot() and friends?

I have several old examples somewhere that used to work (R < ~ 3), but now no 
longer work as before.




Date: Mon, 25 Mar 2024 10:43:29 +1300

From: Paul Murrell mailto:p...@stat.auckland.ac.nz>>

To: "Bickis, Mikelis" mailto:bic...@math.usask.ca>>, 
"r-help@r-project.org"

mailto:r-help@r-project.org>>

Subject: Re: [R] Double buffering plots on Windows

Message-ID: 
mailto:b74c68da-a0b2-47dd-b54f-6b318488c...@stat.auckland.ac.nz>>

Content-Type: text/plain; charset="utf-8"; Format="flowed"



Hi



Take a look at dev.hold() and dev.flush()



Paul


---
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University  Voice: 416 736-2100 x66249
4700 Keele StreetWeb: http://www.datavis.ca | 
@datavisFriendly
Toronto, ONT  M3J 1P3 CANADA


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] as.complex()

2024-03-25 Thread Jeff Newmiller via R-help
?complex

On March 25, 2024 12:23:43 AM PDT, Thomas K  wrote:
>Needing a < , > comparison for imaginary numbers
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] as.complex()

2024-03-25 Thread Iris Simmons
Hi Thomas,


If you want to compare the imaginary portions, you could do:

Im(z1) < Im(z2)

If you want to compare the magnitudes, you could do:

Mod(z1) < Mod(z2)

If you want to compare complex numbers, i.e. z1 < z2, well that just
doesn't make sense.

On Mon, Mar 25, 2024, 10:17 Thomas K  wrote:

> Needing a < , > comparison for imaginary numbers
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] as.complex()

2024-03-25 Thread Thomas K

Needing a < , > comparison for imaginary numbers

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [ESS] Displaying R plots within an Emacs buffer

2024-03-25 Thread Stephen J Eglen via ESS-help




- I works perfectly for me in two different machines (both running
Debian and Emacs 29.2.50)


Thanks for confirming.



- Maybe I am not understanding
https://github.com/sje30/ess-unigd#adjust-to-size-of-buffer--dynamically-update
, but resize of image (on changing frame and window sizes) happens
automagically for me.

- The only minor thing is that, for some reason, the svg is shown in
Fundamental mode (if I find-file other svgs, they are shown as images
directly); I guess it is something with my setup. revert-buffer solves
it.


The code that you have currently just uses the default aspect ratio that 
httpgd() provides, i.e. 720x576 pixels.  The images will rescale as you 
change the buffer, but the aspect ratio won't change.


I've got it now working locally so that the aspect ratio is the same 
size as the window that you use to view the svg.  This I think is more 
flexible.


__
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help


Re: [R] an issue about subsetting a vector

2024-03-25 Thread Richard O'Keefe
For questions like this, go to the manual.

Visit cran.r-project.org
The nav-bar on the left includes
"Documentation/Manuals/FAQ/Contributed".  Click on Manuals.
Look at "An Introduction to R" and click on the HTML link for the
current release
(this is the first link on the page)
Scroll down to see the table of contents.
2.7 Index vectors; selecting and modifying subsets of a data set
is the link you want.  Click on it.
The way it works is that integer(0) is "A vector of positive integral
quantities".
The relevant sentence is "The index vector can be of any length and
the result is of the same length as the index vector."
"Any length" here includes 0.

Your example would be a bit clearer if the elements of a[] were not integers.
So let's make them strings.
> a <- LETTERS[1:5]
> a
[1] "A" "B" "C" "D" "E"
> a[integer(0)]
character(0)

So selecting no elements from a vector of strings gives us a vector
with no strings
(rather than a vector with no integers).
-integer(0)
makes perfect sense and does exactly what anyone should expect:
the result and operand of unary - have the same kind of elements and the
same length and corresponding elements (of which there happen in this
case to be none) are negatives of each other.  So -integer(0) is predictably
the same as integer(0), and a[-integer(0)] is the same as a[integer(0)].

The key point is clarified in section 2.7; _[- _] is NOT special syntax.
What matters in vector[index] is what the *elements* of index are, not
what the syntax of the expression happens to be.

The tricky thing here is that integer(0) is logically BOTH a vector of positive
integer quantities AND a vector of negative integer quantities and the fact that
S (and following it, R) prefers the first interpretation in this
context is just a
fact about S (and following it, R).

It gets even trickier when you start including index value 0 into a vector of
otherwise positive (negative) integers, where in effect the zeros are
ignored.
> a[c(0,0,0,0,0,0)]
character(0)
> a[-c(0,0,0,0,0,0)]
character(0)

On Mon, 25 Mar 2024 at 07:31, Ben Bolker  wrote:
>
> As with a lot of things in R, the behaviour is counterintuitive but
> (arguably) logical. The key (maybe) is that `a[-x]` does not mean "take
> all of the elements of a except those indicated by `x`, but rather,
> "negate x, then take all but the negative elements".  In other words,
>
>   -integer(0)  is   integer(0)  (we multiply *each of the elements of
> integer(0)* by -1, but integer(0) has no elements)
>
>that reduces to a[integer(0)]
>
> and from there you get "select none of the elements".
>
>A related point is explained in the R Inferno
> https://www.burns-stat.com/pages/Tutor/R_inferno.pdf section 8.1.13,
> "negative nothing is something".
>
>See also
>
> https://stackoverflow.com/questions/42615728/subsetting-vector-how-to-programatically-pass-negative-index-safely
>
> https://stackoverflow.com/questions/40026975/subsetting-with-negative-indices-best-practices/40029485#40029485
>
> On 2024-03-24 2:19 p.m., Paulo Barata wrote:
> >
> > To the R-Help list,
> >
> > I would like to have a clarification about an issue that I observe when
> > subsetting a vector. This is R version 4.3.3 on Windows 10.
> >
> > -- Example with a vector:
> >
> >  > a <- 1:5
> >  > a
> > [1] 1 2 3 4 5
> >
> > So we have, with a negative index:
> >  > a[-3]
> > [1] 1 2 4 5
> >
> > But when the index is integer(0), we have this:
> >
> >  > a[integer(0)]
> > integer(0)
> >  > a[-integer(0)]
> > integer(0)
> >
> > When it comes to the function integer(), the R Help file says:
> >
> > "Value: integer creates a integer vector of the specified length. Each
> > element of the vector is equal to 0."
> >
> > But we see below that integer(0) is some kind of null vector, that is,
> > no numbers are represented by integer(0):
> >
> >  > class(integer(0))
> > [1] "integer"
> >  > length(integer(0))
> > [1] 0
> >
> > So my question: in the expression a[-integer(0)], what happens exactly
> > with the index -integer(0)? We see that integer(0), although of class
> > integer, does not represent any numbers, as its length is zero, so it
> > seems to me that it makes no sense to calculate its negative
> > -integer(0). What exactly is -integer(0)?
> >
> > In particular, why a[-integer(0)] is not the whole vector a, that is,
> > [1] 1 2 3 4 5? In the example below, if the invalid index -99 is
> > presented to a, the result is the whole vector:
> >
> >  > a[-99]
> > [1] 1 2 3 4 5
> >
> > If -integer(0) is an invalid index, why do we have this?
> >
> >  > a[-integer(0)]
> > integer(0)
> >
> > Why a[-integer(0)] is not the whole vector a?
> >
> > Thank you very much.
> >
> > Paulo Barata
> >
> > Rio de Janeiro, Brazil
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and