Re: [R] Automatically simulates random numbers (not general) in R?

2019-06-06 Thread Thevaraja, Mayooran
Yes, Now fixed it. Thanks for your help. So my function is given by

start<-function(n){
  #startn <- vector("list", n)
  indx <- 1:N
  start <-sort(sample(indx,1))
  for (i in 1:n) {
if (i<2) {
  start[i] <- sort(sample(indx,1))
} else {
  start[i] <- sort(sample(start[i-1]+1,1))  
}
  }
  start  
}

start(15)

-Original Message-
From: Boris Steipe  
Sent: Friday, 7 June 2019 12:34 PM
To: Thevaraja, Mayooran 
Subject: Re: [R] Automatically simulates random numbers (not general) in R?

You did not initialize the variable "start" inside your function's local scope, 
so the variable "start" is taken to be the function name in the global scope 
and start[i] is therefore a subset operator on a function (i.e. closure). 

":start" is not a good variable name in the first place, and it is poor 
practice to use the same variable name for different objects that you care 
about.


B.

N.b. **Lots** of other issues with your code, e.g. sort() on a single number ...


> On 2019-06-06, at 20:00, Thevaraja, Mayooran  wrote:
> 
> Hello Guys!
> 
> I am wondering about below function which automatically simulates 
> random numbers - given below that manual calculation too. Anyone help me to 
> fix that error. I got that error "object of type 'closure' is not 
> subsettable" So Do you have any ideas?
> 
> 
> 
> Regards
> 
> Mayooran
> 
> 
> 
> #Manual calculation##
> 
> N <- 1e7
> 
> n <- 8
> 
> indx <- 1:N
> 
> start1 <- sort(sample(indx,1))
> 
> 
> 
> start2 <- sort(sample(start1+1,1))
> 
> start3 <- sort(sample(start2+1,1))
> 
> start4 <- sort(sample(start3+1,1))
> 
> start5 <- sort(sample(start4+1,1))
> 
> start6 <- sort(sample(start5+1,1))
> 
> start7 <- sort(sample(start6+1,1))
> 
> start8 <- sort(sample(start7+1,1))
> 
> 
> 
> start1
> 
> start2
> 
> start3
> 
> start4
> 
> start5
> 
> start6
> 
> start7
> 
> start8
> 
> ###Common function#
> 
> start<-function(n){
> 
>  indx <- 1:N
> 
>  for (i in 1:n) {
> 
>if (i<2) {
> 
>  start[i] <- sort(sample(indx,1))
> 
> } else {
> 
>  start[i] <- sort(sample(start[i-1]+1,1))
> 
> }
> 
>  }
> 
> }
> 
> 
> 
> start(8)
> 
> 
>   [[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-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] Automatically simulates random numbers (not general) in R?

2019-06-06 Thread Thevaraja, Mayooran
Hello Guys!

 I am wondering about below function which automatically simulates 
random numbers - given below that manual calculation too. Anyone help me to fix 
that error. I got that error "object of type 'closure' is not subsettable" So 
Do you have any ideas?



Regards

Mayooran



#Manual calculation##

N <- 1e7

n <- 8

indx <- 1:N

start1 <- sort(sample(indx,1))



start2 <- sort(sample(start1+1,1))

start3 <- sort(sample(start2+1,1))

start4 <- sort(sample(start3+1,1))

start5 <- sort(sample(start4+1,1))

start6 <- sort(sample(start5+1,1))

start7 <- sort(sample(start6+1,1))

start8 <- sort(sample(start7+1,1))



start1

start2

start3

start4

start5

start6

start7

start8

###Common function#

start<-function(n){

  indx <- 1:N

  for (i in 1:n) {

if (i<2) {

  start[i] <- sort(sample(indx,1))

} else {

  start[i] <- sort(sample(start[i-1]+1,1))

}

  }

}



start(8)


[[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] Pasting R code lines into labels

2019-06-06 Thread Duncan Murdoch
These look like very fragile suggestions.  Allow x^2 to be an argument 
(named expr, for example) to plotFx, don't force a user to write a 
function in a very particular way.  Then use deparse(substitute(expr)) 
in the title.


Duncan Murdoch

On 06/06/2019 4:33 p.m., Bert Gunter wrote:

Well, if you want to do it this way, note that as written, the y axis
default label isn't "nice," and you should anyway allow for additional
graphical arguments (either way). Also, slightly better I think is to use
the built-in access function, body():

plotFx <- function(x, fun, ...) {
plot(x, fun(x), main = paste0("Plot of y = ", deparse(body(fun))), ...)
}
x <- 1:10
f <- function(x) x^2
plotFx(x, f, col = "red", ylab = "y")

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Jun 6, 2019 at 12:19 PM Marc Schwartz  wrote:


Hi,

Sorry for the misfire on the first attempt.

After seeing the clarifications, I thought about a possible way to do
this, perhaps a little more simply, while encapsulating the plotting in a
function:

plotFx <- function(x, fun) {
   plot(x, fun(x), main = paste0("Plot of y = ", deparse(fun)[2]))
}

So let's say that you have:

x <- 1:10

f <- function(x) x^2
plotFx(x, f)

f <- function(x) cos(x)
plotFx(x, f)

f <- function(x) exp(x) + 1
plotFx(x, f)


In the case of the first function, you get:


deparse(f)

[1] "function (x) " "x^2"

for the second:


deparse(f)

[1] "function (x) " "cos(x)"

and for the third:


deparse(f)

[1] "function (x) " "exp(x) + 1"


Thus, the "deparse(fun)[2]" snippet within the internal paste0() function
call, gets you the second, textual part of the function body, which can
then be passed as a character vector to the titles or other labels as
needed.

A potential gotcha that I would envision, is that the default width in the
character vector resulting from deparse() is 60. Thus, by default the
function body would broken up into multiple character segments, no longer
than approximately 60 characters each. Thus, if you envision that you might
end up with very long formulae on x, you may need to adjust the
width.cutoff argument in the deparse() call, and likely need to do some
additional formatting of the labels in the plot as apropos.

There may be other functional nuances that I am missing here, but this may
be a suitable approach.

Regards,

Marc



On Jun 6, 2019, at 2:11 PM, Bert Gunter  wrote:

Yes, plot(z,y,..)

Bert

On Thu, Jun 6, 2019 at 9:21 AM Nick Wray 

wrote:



Thanks Bert, that is exactly what I wanted.  I think that you meant
plot(z,y... in the last line?

Nick

On 06 June 2019 at 17:13 Bert Gunter  wrote:

... and if you wanted too streamline the process, something like the
following could be encapsulated in a function:

fun <- quote(exp(x))
z <- 1:9
y <- eval(fun,list(x = z) )
plot(x, y, main = paste("Plot of y =", deparse(fun)))

Further details can be found in the "Computing on the Language" section

of

the "R Language Reference" manual or from suitable tutorials on the web.

Bert Gunter

"The trouble with having an open mind is that people keep coming along

and

sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Jun 6, 2019 at 8:55 AM Nick Wray via R-help <

r-help@r-project.org>

wrote:

Thanks but that's not quite what I meant
I am trying out different functions and they don't necessarily vary in a
regular way (like say all being powers of x where it'd be simple to just
have a vector for the powers you want)
So I might have
y<-x^2
y<-cos(x)
y<-exp(x+1)
What I am after is a way of running these functions and then calling

each

one into the labelling for the appropriate graph as I plot it.  So then

I

would have something like
mainlab<-paste("Plot of ",function in question)
...? Thanks Nick


On 06 June 2019 at 16:40 Marc Schwartz < marc_schwa...@me.com> wrote:




On Jun 6, 2019, at 11:19 AM, Nick Wray via R-help <

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


Is there any way of taking a line of r code (eg y<-x^2) and pasting

that line of code, as is, into a label, so that for example I could then
have a plot label "Plot of y<-x^2"?


Thanks Nick Wray



Hi,

See ?plotmath

An example:

x <- 1:10
y <- x^2

plot(x, y, main = expression(paste("Plot of ", y %<-% x^2)))


There are other incantations and examples on the help page above.

Regards,

Marc Schwartz






[[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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help

Re: [R] Open a file which name contains a tilde

2019-06-06 Thread Duncan Murdoch

On 06/06/2019 5:04 p.m., Richard O'Keefe wrote:

How can expanding tildes anywhere but the beginning of a file name NOT be
considered a bug?


It looks like a bug in R, but not necessarily a bug in libreadline:  we 
may just be using tilde_expand improperly.


Duncan Murdoch




On Thu, 6 Jun 2019 at 23:04, Ivan Krylov  wrote:


On Wed, 5 Jun 2019 18:07:15 +0200
Frank Schwidom  wrote:


+> path.expand("a ~ b")
[1] "a /home/user b"



How can I switch off any file crippling activity?


It doesn't seem to be possible if readline is enabled and works
correctly.

Calls to path.expand [1] end up [2] in R_ExpandFileName [3], which
calls R_ExpandFileName_readline [4], which uses libreadline function
tilde_expand [5]. tilde_expand seems to be designed to expand '~'
anywhere in the string it is handed, i.e. operate on whole command
lines, not file paths.

I am taking the liberty of Cc-ing R-devel in case this can be
considered a bug.

--
Best regards,
Ivan

[1]

https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807

[2]

https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915

[3]

https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-unix.c#L147

[4]

https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-std.c#L494

[5]
https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187

__
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-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] Open a file which name contains a tilde

2019-06-06 Thread Richard O'Keefe
How can expanding tildes anywhere but the beginning of a file name NOT be
considered a bug?


On Thu, 6 Jun 2019 at 23:04, Ivan Krylov  wrote:

> On Wed, 5 Jun 2019 18:07:15 +0200
> Frank Schwidom  wrote:
>
> > +> path.expand("a ~ b")
> > [1] "a /home/user b"
>
> > How can I switch off any file crippling activity?
>
> It doesn't seem to be possible if readline is enabled and works
> correctly.
>
> Calls to path.expand [1] end up [2] in R_ExpandFileName [3], which
> calls R_ExpandFileName_readline [4], which uses libreadline function
> tilde_expand [5]. tilde_expand seems to be designed to expand '~'
> anywhere in the string it is handed, i.e. operate on whole command
> lines, not file paths.
>
> I am taking the liberty of Cc-ing R-devel in case this can be
> considered a bug.
>
> --
> Best regards,
> Ivan
>
> [1]
>
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807
>
> [2]
>
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915
>
> [3]
>
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-unix.c#L147
>
> [4]
>
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-std.c#L494
>
> [5]
> https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187
>
> __
> 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.


Re: [R] Pasting R code lines into labels

2019-06-06 Thread Bert Gunter
Well, if you want to do it this way, note that as written, the y axis
default label isn't "nice," and you should anyway allow for additional
graphical arguments (either way). Also, slightly better I think is to use
the built-in access function, body():

plotFx <- function(x, fun, ...) {
   plot(x, fun(x), main = paste0("Plot of y = ", deparse(body(fun))), ...)
}
x <- 1:10
f <- function(x) x^2
plotFx(x, f, col = "red", ylab = "y")

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Jun 6, 2019 at 12:19 PM Marc Schwartz  wrote:

> Hi,
>
> Sorry for the misfire on the first attempt.
>
> After seeing the clarifications, I thought about a possible way to do
> this, perhaps a little more simply, while encapsulating the plotting in a
> function:
>
> plotFx <- function(x, fun) {
>   plot(x, fun(x), main = paste0("Plot of y = ", deparse(fun)[2]))
> }
>
> So let's say that you have:
>
> x <- 1:10
>
> f <- function(x) x^2
> plotFx(x, f)
>
> f <- function(x) cos(x)
> plotFx(x, f)
>
> f <- function(x) exp(x) + 1
> plotFx(x, f)
>
>
> In the case of the first function, you get:
>
> > deparse(f)
> [1] "function (x) " "x^2"
>
> for the second:
>
> > deparse(f)
> [1] "function (x) " "cos(x)"
>
> and for the third:
>
> > deparse(f)
> [1] "function (x) " "exp(x) + 1"
>
>
> Thus, the "deparse(fun)[2]" snippet within the internal paste0() function
> call, gets you the second, textual part of the function body, which can
> then be passed as a character vector to the titles or other labels as
> needed.
>
> A potential gotcha that I would envision, is that the default width in the
> character vector resulting from deparse() is 60. Thus, by default the
> function body would broken up into multiple character segments, no longer
> than approximately 60 characters each. Thus, if you envision that you might
> end up with very long formulae on x, you may need to adjust the
> width.cutoff argument in the deparse() call, and likely need to do some
> additional formatting of the labels in the plot as apropos.
>
> There may be other functional nuances that I am missing here, but this may
> be a suitable approach.
>
> Regards,
>
> Marc
>
>
> > On Jun 6, 2019, at 2:11 PM, Bert Gunter  wrote:
> >
> > Yes, plot(z,y,..)
> >
> > Bert
> >
> > On Thu, Jun 6, 2019 at 9:21 AM Nick Wray 
> wrote:
> >
> >> Thanks Bert, that is exactly what I wanted.  I think that you meant
> >> plot(z,y... in the last line?
> >>
> >> Nick
> >>
> >> On 06 June 2019 at 17:13 Bert Gunter  wrote:
> >>
> >> ... and if you wanted too streamline the process, something like the
> >> following could be encapsulated in a function:
> >>
> >> fun <- quote(exp(x))
> >> z <- 1:9
> >> y <- eval(fun,list(x = z) )
> >> plot(x, y, main = paste("Plot of y =", deparse(fun)))
> >>
> >> Further details can be found in the "Computing on the Language" section
> of
> >> the "R Language Reference" manual or from suitable tutorials on the web.
> >>
> >> Bert Gunter
> >>
> >> "The trouble with having an open mind is that people keep coming along
> and
> >> sticking things into it."
> >> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >>
> >>
> >> On Thu, Jun 6, 2019 at 8:55 AM Nick Wray via R-help <
> r-help@r-project.org>
> >> wrote:
> >>
> >> Thanks but that's not quite what I meant
> >> I am trying out different functions and they don't necessarily vary in a
> >> regular way (like say all being powers of x where it'd be simple to just
> >> have a vector for the powers you want)
> >> So I might have
> >> y<-x^2
> >> y<-cos(x)
> >> y<-exp(x+1)
> >> What I am after is a way of running these functions and then calling
> each
> >> one into the labelling for the appropriate graph as I plot it.  So then
> I
> >> would have something like
> >> mainlab<-paste("Plot of ",function in question)
> >> ...? Thanks Nick
> >>
> >>> On 06 June 2019 at 16:40 Marc Schwartz < marc_schwa...@me.com> wrote:
> >>>
> >>>
> >>>
>  On Jun 6, 2019, at 11:19 AM, Nick Wray via R-help <
> >> r-help@r-project.org> wrote:
> 
>  Is there any way of taking a line of r code (eg y<-x^2) and pasting
> >> that line of code, as is, into a label, so that for example I could then
> >> have a plot label "Plot of y<-x^2"?
> 
>  Thanks Nick Wray
> >>>
> >>>
> >>> Hi,
> >>>
> >>> See ?plotmath
> >>>
> >>> An example:
> >>>
> >>> x <- 1:10
> >>> y <- x^2
> >>>
> >>> plot(x, y, main = expression(paste("Plot of ", y %<-% x^2)))
> >>>
> >>>
> >>> There are other incantations and examples on the help page above.
> >>>
> >>> Regards,
> >>>
> >>> Marc Schwartz
> >>>
>
>

[[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 

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
Hi Rui,

Yes! This worked just fine! Thank you so, so much for your time and patience! 

-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 3:25 pm
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

Try this.


values_to_plot <- c("onepctCO2MEDIAN", "RCP4.5MEDIAN", "RCP8.5MEDIAN")
sub_df <- subset(NewestdataUltra, L1 %in% values_to_plot)

ggplot(sub_df, aes(x, value, colour = L1)) +
  geom_point() +
  scale_color_manual(values = c("green", "red", "blue")) +
  geom_smooth(method = lm)


If you have more L1 values to plot, add more colors. The number of 
colors must be equal to

length(values_to_plot)


Hope this helps,

Rui Barradas

Às 17:49 de 06/06/19, rain1...@aim.com escreveu:
> Hi Rui, NewestdataUltra looks like this (Note that "HistoricalMEDIAN" is 
> hidden, but it follows "RCP8.5MEDIAN" listing the same way): x variable 
> value L1 1 0.0 y 0. onepctCO2MEDIAN 2 0.006794447 y 
> 4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607 onepctCO2MEDIAN 4 
> 0.022087920 y 6.63491326 onepctCO2MEDIAN 5 0.030797357 y -1.24295056 
> onepctCO2MEDIAN 6 0.038451072 y 1.56433744 onepctCO2MEDIAN 7 0.048087904 
> y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y 2.20700446 onepctCO2MEDIAN 
> 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10 0.080524530 y -1.09135062 
> onepctCO2MEDIAN 11 0.092760246 y 0.40999399 onepctCO2MEDIAN 12 
> 0.103789609 y -0.12597268 onepctCO2MEDIAN 13 0.116953168 y -2.41382534 
> onepctCO2MEDIAN 14 0.129253298 y 7.08902570 onepctCO2MEDIAN 15 
> 0.141710050 y -0.75935388 onepctCO2MEDIAN 16 0.156002052 y 0.04544160 
> onepctCO2MEDIAN 17 0.170648172 y -1.53496826 onepctCO2MEDIAN 18 
> 0.185318425 y 6.55242014 onepctCO2MEDIAN 19 0.199463055 y -0.83125628 
> onepctCO2MEDIAN 20 0.213513337 y -2.50991826 onepctCO2MEDIAN 21 
> 0.228839271 y 0.13659682 onepctCO2MEDIAN 22 0.246981293 y -1.37198445 
> onepctCO2MEDIAN 23 0.263012767 y -0.87129883 onepctCO2MEDIAN 24 
> 0.278505564 y 0.66325836 onepctCO2MEDIAN 25 0.293658361 y 0.79380363 
> onepctCO2MEDIAN 26 0.310747266 y 3.48806374 onepctCO2MEDIAN 27 
> 0.325990349 y -4.46122081 onepctCO2MEDIAN 28 0.342517540 y 0.08717340 
> onepctCO2MEDIAN 29 0.362751633 y -1.41715777 onepctCO2MEDIAN 30 
> 0.380199537 y -0.99565082 onepctCO2MEDIAN 31 0.394992948 y 0.32155262 
> onepctCO2MEDIAN 32 0.414373398 y 3.14038657 onepctCO2MEDIAN 33 
> 0.430690214 y -0.73760988 onepctCO2MEDIAN 34 0.449738145 y -2.48605407 
> onepctCO2MEDIAN 35 0.470167458 y -3.42358584 onepctCO2MEDIAN 36 
> 0.489019871 y 0.48247475 onepctCO2MEDIAN 37 0.507242471 y -0.97853863 
> onepctCO2MEDIAN 38 0.524314284 y 8.53596838 onepctCO2MEDIAN 39 
> 0.543750525 y 5.48447420 onepctCO2MEDIAN 40 0.564234197 y 3.21493666 
> onepctCO2MEDIAN 41 0.583679616 y 3.91689160 onepctCO2MEDIAN 42 
> 0.601459444 y 4.49070196 onepctCO2MEDIAN 43 0.619924664 y 6.54104103 
> onepctCO2MEDIAN 44 0.639932007 y 4.80686500 onepctCO2MEDIAN 45 
> 0.661347181 y 8.15101701 onepctCO2MEDIAN 46 0.684117317 y 0.26974132 
> onepctCO2MEDIAN 47 0.704829752 y -0.18075007 onepctCO2MEDIAN 48 
> 0.725045770 y 9.71812491 onepctCO2MEDIAN 49 0.745165825 y 1.54064657 
> onepctCO2MEDIAN 50 0.765016139 y -1.64760409 onepctCO2MEDIAN 51 
> 0.783461511 y 4.80246029 onepctCO2MEDIAN 52 0.806382924 y 4.04215160 
> onepctCO2MEDIAN 53 0.829241335 y 9.37565122 onepctCO2MEDIAN 54 
> 0.849924415 y 5.33050497 onepctCO2MEDIAN 55 0.871352434 y 7.54458026 
> onepctCO2MEDIAN 56 0.893632233 y 6.46795471 onepctCO2MEDIAN 57 
> 0.916052133 y 2.80960651 onepctCO2MEDIAN 58 0.938579470 y 5.39216613 
> onepctCO2MEDIAN 59 0.959907651 y 7.20436888 onepctCO2MEDIAN 60 
> 0.981643587 y 3.33508065 onepctCO2MEDIAN 61 1.004116774 y 8.86907070 
> onepctCO2MEDIAN 62 1.028363466 y 1.78612989 onepctCO2MEDIAN 63 
> 1.054009140 y 6.25550382 onepctCO2MEDIAN 64 1.072440803 y 7.60792365 
> onepctCO2MEDIAN 65 1.094457805 y 7.68714831 onepctCO2MEDIAN 66 
> 1.123176277 y 4.77877639 onepctCO2MEDIAN 67 1.149430871 y 12.71105018 
> onepctCO2MEDIAN 68 1.170912921 y -0.71562844 onepctCO2MEDIAN 69 
> 1.196743071 y 1.64908992 onepctCO2MEDIAN 70 1.218625903 y 3.03630241 
> onepctCO2MEDIAN 71 1.241868377 y 4.29747688 onepctCO2MEDIAN 72 
> 1.267941594 y 1.95437781 onepctCO2MEDIAN 73 1.290708780 y 3.99869637 
> onepctCO2MEDIAN 74 1.31389 y 4.51794725 onepctCO2MEDIAN 75 
> 1.339045882 y 0.93379048 onepctCO2MEDIAN 76 1.362803459 y 3.30507700 
> onepctCO2MEDIAN 77 1.384450197 y 3.54229702 onepctCO2MEDIAN 78 
> 1.409720302 y 5.99736597 onepctCO2MEDIAN 79 1.435851157 y 0.50818686 
> onepctCO2MEDIAN 80 1.455592215 y 7.96616301 onepctCO2MEDIAN 81 
> 1.479495347 y 9.94604963 onepctCO2MEDIAN 82 1.506051958 y 3.79083717 
> onepctCO2MEDIAN 83 1.525728464 y 2.57358469 onepctCO2MEDIAN 84 
> 1.549362063 y 10.14049742 onepctCO2MEDIAN 85 1.573440671 y 13.74083036 
> onepctCO2MEDIAN 86 1.600278735 y 0.93357712 onepctCO2MEDIAN 87 
> 1.623879492 y 9.75887417 onepctCO2MEDIAN 88 1.650029302 y 1.27693947 
> onepctCO2MEDIAN 89 1.672362328 y 

Re: [R] max size of a file that R can open to work

2019-06-06 Thread Jeff Newmiller
Technically "opening" a file does not involve reading it into memory at all, so 
any limits would arise from the OS.

As for "reading" the file, the amount of virtual memory [1] is the key factor, 
but different file formats can require more or less overhead memory to parse 
the data. Also, different functions may utilize available memory more or less 
efficiently, so your mileage may vary depending on what base or contributed 
functions you use to read the data.

[1] Virtual memory is a very OS-specific thing... but if you depend on it very 
much your performance will suffer considerably.

On June 5, 2019 2:38:29 PM PDT, Ricardo Lopez  wrote:
>Hello, I´d like to ask you if the max size of a file that R can open 
>or
>import to work depends of the memory RAM??  or has other restriction???
>
>Thank you very much
>
>   [[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.

-- 
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] Including a large number of variables in a formula.

2019-06-06 Thread Rolando I. Valdez via R-help
The first idea works perfect.

Thank you!.

El mié., 5 jun. 2019 a las 1:07, peter dalgaard ()
escribió:

> Two ideas:
>
> nn <- names(wageszm14)
> lvadd <- nn[grep("^lvacb", nn)]
>
> or
>
> lvadd <- paste0("lvacb", 23:81)
> lvadd <- lvadd[lvadd %in% names(wageszm14)]
>
> > On 5 Jun 2019, at 06:46 , Rolando I. Valdez via R-help <
> r-help@r-project.org> wrote:
> >
> > Hello,
> >
> > I have almost 40 variables that I am trying to include in a formula.
> >
> > I tried to include them using as.formula(), however the variables do not
> > follow a patter in the name. e.g. These variables are named like: lvacb23
> > lvacb30 lvacb300  lvacb40 .  lvacb81.
> >
> >> lvadd <- paste0("lvacb", 23:81)
> >> (fmla <- as.formula(paste("lwage ~ ", paste(lvadd, collapse = "+"
> >> fit <- lm(fmla, data = wageszm14)
> > Error in eval(predvars, data, env) : object 'lvacb24' not found
> >
> > The variable lvacb24 doesn't exist, because from lvacb23 it jumps to
> > lvacb30.
> >
> > Thanks in advance for any help.
> > --
> > Rolando Valdez
> > Facultad de Economía y Relaciones Internacionales
> > Universidad Autónoma de Baja California
> >
> >   [[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.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>
>
>
>
>
>
>
>
>

-- 
Rolando Valdez
Facultad de Economía y Relaciones Internacionales
Universidad Autónoma de Baja California

[[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] Plotting more than one regression line in ggplot

2019-06-06 Thread Rui Barradas

Hello,

Try this.


values_to_plot <- c("onepctCO2MEDIAN", "RCP4.5MEDIAN", "RCP8.5MEDIAN")
sub_df <- subset(NewestdataUltra, L1 %in% values_to_plot)

ggplot(sub_df, aes(x, value, colour = L1)) +
  geom_point() +
  scale_color_manual(values = c("green", "red", "blue")) +
  geom_smooth(method = lm)


If you have more L1 values to plot, add more colors. The number of 
colors must be equal to


length(values_to_plot)


Hope this helps,

Rui Barradas

Às 17:49 de 06/06/19, rain1...@aim.com escreveu:
Hi Rui, NewestdataUltra looks like this (Note that "HistoricalMEDIAN" is 
hidden, but it follows "RCP8.5MEDIAN" listing the same way): x variable 
value L1 1 0.0 y 0. onepctCO2MEDIAN 2 0.006794447 y 
4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607 onepctCO2MEDIAN 4 
0.022087920 y 6.63491326 onepctCO2MEDIAN 5 0.030797357 y -1.24295056 
onepctCO2MEDIAN 6 0.038451072 y 1.56433744 onepctCO2MEDIAN 7 0.048087904 
y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y 2.20700446 onepctCO2MEDIAN 
9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10 0.080524530 y -1.09135062 
onepctCO2MEDIAN 11 0.092760246 y 0.40999399 onepctCO2MEDIAN 12 
0.103789609 y -0.12597268 onepctCO2MEDIAN 13 0.116953168 y -2.41382534 
onepctCO2MEDIAN 14 0.129253298 y 7.08902570 onepctCO2MEDIAN 15 
0.141710050 y -0.75935388 onepctCO2MEDIAN 16 0.156002052 y 0.04544160 
onepctCO2MEDIAN 17 0.170648172 y -1.53496826 onepctCO2MEDIAN 18 
0.185318425 y 6.55242014 onepctCO2MEDIAN 19 0.199463055 y -0.83125628 
onepctCO2MEDIAN 20 0.213513337 y -2.50991826 onepctCO2MEDIAN 21 
0.228839271 y 0.13659682 onepctCO2MEDIAN 22 0.246981293 y -1.37198445 
onepctCO2MEDIAN 23 0.263012767 y -0.87129883 onepctCO2MEDIAN 24 
0.278505564 y 0.66325836 onepctCO2MEDIAN 25 0.293658361 y 0.79380363 
onepctCO2MEDIAN 26 0.310747266 y 3.48806374 onepctCO2MEDIAN 27 
0.325990349 y -4.46122081 onepctCO2MEDIAN 28 0.342517540 y 0.08717340 
onepctCO2MEDIAN 29 0.362751633 y -1.41715777 onepctCO2MEDIAN 30 
0.380199537 y -0.99565082 onepctCO2MEDIAN 31 0.394992948 y 0.32155262 
onepctCO2MEDIAN 32 0.414373398 y 3.14038657 onepctCO2MEDIAN 33 
0.430690214 y -0.73760988 onepctCO2MEDIAN 34 0.449738145 y -2.48605407 
onepctCO2MEDIAN 35 0.470167458 y -3.42358584 onepctCO2MEDIAN 36 
0.489019871 y 0.48247475 onepctCO2MEDIAN 37 0.507242471 y -0.97853863 
onepctCO2MEDIAN 38 0.524314284 y 8.53596838 onepctCO2MEDIAN 39 
0.543750525 y 5.48447420 onepctCO2MEDIAN 40 0.564234197 y 3.21493666 
onepctCO2MEDIAN 41 0.583679616 y 3.91689160 onepctCO2MEDIAN 42 
0.601459444 y 4.49070196 onepctCO2MEDIAN 43 0.619924664 y 6.54104103 
onepctCO2MEDIAN 44 0.639932007 y 4.80686500 onepctCO2MEDIAN 45 
0.661347181 y 8.15101701 onepctCO2MEDIAN 46 0.684117317 y 0.26974132 
onepctCO2MEDIAN 47 0.704829752 y -0.18075007 onepctCO2MEDIAN 48 
0.725045770 y 9.71812491 onepctCO2MEDIAN 49 0.745165825 y 1.54064657 
onepctCO2MEDIAN 50 0.765016139 y -1.64760409 onepctCO2MEDIAN 51 
0.783461511 y 4.80246029 onepctCO2MEDIAN 52 0.806382924 y 4.04215160 
onepctCO2MEDIAN 53 0.829241335 y 9.37565122 onepctCO2MEDIAN 54 
0.849924415 y 5.33050497 onepctCO2MEDIAN 55 0.871352434 y 7.54458026 
onepctCO2MEDIAN 56 0.893632233 y 6.46795471 onepctCO2MEDIAN 57 
0.916052133 y 2.80960651 onepctCO2MEDIAN 58 0.938579470 y 5.39216613 
onepctCO2MEDIAN 59 0.959907651 y 7.20436888 onepctCO2MEDIAN 60 
0.981643587 y 3.33508065 onepctCO2MEDIAN 61 1.004116774 y 8.86907070 
onepctCO2MEDIAN 62 1.028363466 y 1.78612989 onepctCO2MEDIAN 63 
1.054009140 y 6.25550382 onepctCO2MEDIAN 64 1.072440803 y 7.60792365 
onepctCO2MEDIAN 65 1.094457805 y 7.68714831 onepctCO2MEDIAN 66 
1.123176277 y 4.77877639 onepctCO2MEDIAN 67 1.149430871 y 12.71105018 
onepctCO2MEDIAN 68 1.170912921 y -0.71562844 onepctCO2MEDIAN 69 
1.196743071 y 1.64908992 onepctCO2MEDIAN 70 1.218625903 y 3.03630241 
onepctCO2MEDIAN 71 1.241868377 y 4.29747688 onepctCO2MEDIAN 72 
1.267941594 y 1.95437781 onepctCO2MEDIAN 73 1.290708780 y 3.99869637 
onepctCO2MEDIAN 74 1.31389 y 4.51794725 onepctCO2MEDIAN 75 
1.339045882 y 0.93379048 onepctCO2MEDIAN 76 1.362803459 y 3.30507700 
onepctCO2MEDIAN 77 1.384450197 y 3.54229702 onepctCO2MEDIAN 78 
1.409720302 y 5.99736597 onepctCO2MEDIAN 79 1.435851157 y 0.50818686 
onepctCO2MEDIAN 80 1.455592215 y 7.96616301 onepctCO2MEDIAN 81 
1.479495347 y 9.94604963 onepctCO2MEDIAN 82 1.506051958 y 3.79083717 
onepctCO2MEDIAN 83 1.525728464 y 2.57358469 onepctCO2MEDIAN 84 
1.549362063 y 10.14049742 onepctCO2MEDIAN 85 1.573440671 y 13.74083036 
onepctCO2MEDIAN 86 1.600278735 y 0.93357712 onepctCO2MEDIAN 87 
1.623879492 y 9.75887417 onepctCO2MEDIAN 88 1.650029302 y 1.27693947 
onepctCO2MEDIAN 89 1.672362328 y 13.49709060 onepctCO2MEDIAN 90 
1.700221121 y 10.20875018 onepctCO2MEDIAN 91 1.724793375 y 1.68112753 
onepctCO2MEDIAN 92 1.751070559 y 6.11789915 onepctCO2MEDIAN 93 
1.778022110 y -0.15676262 onepctCO2MEDIAN 94 1.803022087 y 3.82374792 
onepctCO2MEDIAN 95 1.830668867 y 4.43314679 onepctCO2MEDIAN 96 
1.855736911 y 5.97907067 onepctCO2MEDIAN 97 1.882615030 y 11.31043325 

Re: [R] Pasting R code lines into labels

2019-06-06 Thread Marc Schwartz via R-help
Hi,

Sorry for the misfire on the first attempt.

After seeing the clarifications, I thought about a possible way to do this, 
perhaps a little more simply, while encapsulating the plotting in a function:

plotFx <- function(x, fun) {
  plot(x, fun(x), main = paste0("Plot of y = ", deparse(fun)[2]))
}

So let's say that you have:

x <- 1:10

f <- function(x) x^2
plotFx(x, f)

f <- function(x) cos(x)
plotFx(x, f)

f <- function(x) exp(x) + 1
plotFx(x, f)


In the case of the first function, you get:

> deparse(f)
[1] "function (x) " "x^2" 

for the second:

> deparse(f)
[1] "function (x) " "cos(x)" 

and for the third:

> deparse(f)
[1] "function (x) " "exp(x) + 1" 


Thus, the "deparse(fun)[2]" snippet within the internal paste0() function call, 
gets you the second, textual part of the function body, which can then be 
passed as a character vector to the titles or other labels as needed.

A potential gotcha that I would envision, is that the default width in the 
character vector resulting from deparse() is 60. Thus, by default the function 
body would broken up into multiple character segments, no longer than 
approximately 60 characters each. Thus, if you envision that you might end up 
with very long formulae on x, you may need to adjust the width.cutoff argument 
in the deparse() call, and likely need to do some additional formatting of the 
labels in the plot as apropos.

There may be other functional nuances that I am missing here, but this may be a 
suitable approach.

Regards,

Marc


> On Jun 6, 2019, at 2:11 PM, Bert Gunter  wrote:
> 
> Yes, plot(z,y,..)
> 
> Bert
> 
> On Thu, Jun 6, 2019 at 9:21 AM Nick Wray  wrote:
> 
>> Thanks Bert, that is exactly what I wanted.  I think that you meant
>> plot(z,y... in the last line?
>> 
>> Nick
>> 
>> On 06 June 2019 at 17:13 Bert Gunter  wrote:
>> 
>> ... and if you wanted too streamline the process, something like the
>> following could be encapsulated in a function:
>> 
>> fun <- quote(exp(x))
>> z <- 1:9
>> y <- eval(fun,list(x = z) )
>> plot(x, y, main = paste("Plot of y =", deparse(fun)))
>> 
>> Further details can be found in the "Computing on the Language" section of
>> the "R Language Reference" manual or from suitable tutorials on the web.
>> 
>> Bert Gunter
>> 
>> "The trouble with having an open mind is that people keep coming along and
>> sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>> 
>> 
>> On Thu, Jun 6, 2019 at 8:55 AM Nick Wray via R-help < r-help@r-project.org>
>> wrote:
>> 
>> Thanks but that's not quite what I meant
>> I am trying out different functions and they don't necessarily vary in a
>> regular way (like say all being powers of x where it'd be simple to just
>> have a vector for the powers you want)
>> So I might have
>> y<-x^2
>> y<-cos(x)
>> y<-exp(x+1)
>> What I am after is a way of running these functions and then calling each
>> one into the labelling for the appropriate graph as I plot it.  So then I
>> would have something like
>> mainlab<-paste("Plot of ",function in question)
>> ...? Thanks Nick
>> 
>>> On 06 June 2019 at 16:40 Marc Schwartz < marc_schwa...@me.com> wrote:
>>> 
>>> 
>>> 
 On Jun 6, 2019, at 11:19 AM, Nick Wray via R-help <
>> r-help@r-project.org> wrote:
 
 Is there any way of taking a line of r code (eg y<-x^2) and pasting
>> that line of code, as is, into a label, so that for example I could then
>> have a plot label "Plot of y<-x^2"?
 
 Thanks Nick Wray
>>> 
>>> 
>>> Hi,
>>> 
>>> See ?plotmath
>>> 
>>> An example:
>>> 
>>> x <- 1:10
>>> y <- x^2
>>> 
>>> plot(x, y, main = expression(paste("Plot of ", y %<-% x^2)))
>>> 
>>> 
>>> There are other incantations and examples on the help page above.
>>> 
>>> Regards,
>>> 
>>> Marc Schwartz
>>> 

__
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-es] Incluir un rango de varias variables explicativas a un modelo

2019-06-06 Thread Rolando Valdez
Sí, más o menos así lo resolví:

nn <-names(wageszm14)
lvadd <- nn[grep("^lvadd", nn)]
(eqreg <- as.formula(paste("lwage ~ age + educ + percmen + marr + natlang
+", paste(lvadd, collapse = "+"
lwage ~ age + educ + percmen + marr + natlang + lvadd23_pot23 +
lvadd3133_pot3133 + lvadd_commer_pot_commer +
lvadd_communic_pot_communic +
lvadd_hserv_pot_hserv + lvadd62_pot62 + lvadd_host_pot_host +
lvadd81_pot81

Con eso quedó resuelto.

Gracias a todos por sus respuestas.



El mié., 5 de jun. de 2019 a la(s) 14:15, Juan Abasolo (juan.abas...@ehu.eus)
escribió:

> Meto cuchara y disculpen si es una tontería:
> Y si creás un objeto con los nombres de las variables? y si solamente te
> interesan las que cumplan no sé qué característica en el nombre, pedirlo.
>
> pabuscar <- sort(names(tudataframe))
> pabuscar[grep('x', pabuscar)]
>
> Los que saben seguro que lo hacen más lindo, pero yo creo que eso te
> funcionaría y no es difacil. Suerte
>
> Hau idatzi du Rolando Valdez (rvald...@gmail.com) erabiltzaileak (2019
> eka. 4, ar. (05:43)):
>
>> Hola, gracias por la respuesta,
>>
>> No me funcionó debido a que los nombres de las variables no están
>> seriadas,
>> es decir, los nombres de las variables son del tipo: x23 x25 x30, x301
>> x320, x80. Entonces me da este error:
>> Error in eval(predvars, data, env) : object 'pot24' not found. Debido a
>> que
>> pot24 no existe, ya que de pot23 se brinca a pot30.
>>
>> En Stata es algo muy simple de hacer, solo tengo que especificar gl
>> indepvars "x23-x80" y ya. En R no logro hacerlo.
>>
>> ¿Alguna otra sugerencia?
>>
>> Gracias de antemano.
>>
>> El lun., 3 de jun. de 2019 a la(s) 04:50, Carlos Ortega (
>> c...@qualityexcellence.es) escribió:
>>
>> > Hola,
>> >
>> > Mira la función "*as.formula()*".
>> > Incluye un ejemplo muy parecido a lo que estás queriendo hacer.
>> >
>> > Saludos,
>> > Carlos Ortega
>> > www.qualityexcellence.es
>> >
>> > El lun., 3 jun. 2019 a las 1:00, Rolando Valdez ()
>> > escribió:
>> >
>> >> Hola,
>> >>
>> >> Quiero especificar una ecuación con varias variables explicativas de
>> una
>> >> manera eficiente sin necesidad de escribir todas y cada una. Tengo un
>> >> conjunto de variables (junto con otras) dentro de una base de datos
>> que se
>> >> llaman pot23 pot311 pot312 pot 316 pot317... pot80. No
>> >> necesariamente están secuenciadas. Quisiera saber cómo indicar que
>> incluya
>> >> todas las variables de pot23 a pot80 en una ecuación.
>> >>
>> >> He intentado lo siguiente, pero no funciona:
>> >>
>> >> > pots <- paste("pot",23:321, sep="")
>> >> > eqreg2 <- lwage~SEXO+EDAD+HLENGUA+ESCOACUM+marr+wageszm14[,pots]
>> >> > fit <- qregspiv(eqreg2, shpfile = zm15, tau = 0.5, nboot = 70, data =
>> >> wageszm14)
>> >> Error: Can't find columns `pot24`, `pot25`, `pot26`, `pot27`, `pot28`,
>> ...
>> >> (and 273 more) in `.data`.
>> >>
>> >> De igual forma, después estaría interesado en obtener el logaritmo de
>> >> todas
>> >> esas variables pot~
>> >>
>> >> Gracias de antemano por cualquier tipo de ayuda.
>> >>
>> >> --
>> >> Rol~
>> >>
>> >> [[alternative HTML version deleted]]
>> >>
>> >> ___
>> >> R-help-es mailing list
>> >> R-help-es@r-project.org
>> >> https://stat.ethz.ch/mailman/listinfo/r-help-es
>> >>
>> >
>> >
>> > --
>> > Saludos,
>> > Carlos Ortega
>> > www.qualityexcellence.es
>> >
>>
>>
>> --
>> Rol~
>>
>> [[alternative HTML version deleted]]
>>
>> ___
>> R-help-es mailing list
>> R-help-es@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>>
>
>
> --
> Juan Abasolo
>
> Hizkuntzaren eta Literaturaren Didaktika Saila | EUDIA ikerketa taldea
> Bilboko Hezkuntza Fakultatea
> Euskal Herriko Unibertsitatea
> UPV/EHU
>
> Sarriena auzoa z/g 48940 - Leioa (Bizkaia)
>
> T: (+34) 94 601 7567
> Telegram: @JuanAbasolo
> Skype: abasolo72
>
> Tutoretza ordutegia 
>


-- 
Rol~

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] Pass an equation as an argument of a sub-function

2019-06-06 Thread Bert Gunter
It is perhaps worth saying that my prior suggestion may not be the best
strategy for doing what you want. The previous poster needed the actual
expression to deparse as a label. If you only need the expression as a
function to be evaluated, it may be better to pass the argument as a
function -- a feature of functional programming languages like R. For
example:

top <- function(x, fun)fun(x)
f <- function(x)x^2 + sin(x)
top(1:4, f)

Again, appropriate sections of the R Language Reference or web tutorials
provide details.


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Jun 6, 2019 at 11:24 AM Bert Gunter  wrote:

> See here for almost the same issue:
>
>
> http://r.789695.n4.nabble.com/Pasting-R-code-lines-into-labels-td4757446.html
>
> Same answer: pass the unevaluated formula (i.e. an R expression) using
> substitute/quote. Then evaluate it appropriately using eval. Same
> references.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, Jun 6, 2019 at 11:08 AM Frank S.  wrote:
>
>> Dear all,
>>
>> I have defined an R function g(y) wich in turn is inside other R function
>> f(x). The function g(y) depends on an
>> equation, and I would like to know if such an equation could be passed as
>> an argument of the main function
>> (taking into account that we should change the variable "x" to "y").
>> As an example, I have:
>>
>> function(x) { # Main function, called f(x)
>>
>>   -  (code)
>>
>>   function(y) {# Sub-function, called g(y)
>> -  (code)
>> eq <- y^2 -3*y
>> - (code)
>>   }
>>
>>   - (code)
>>
>> }
>>
>> In summary, I would like to know is there is any way to:
>> Put the equation "eq" as an argument of the main function f(x).
>>
>>
>> Thank you very much!
>>
>> Frank
>>
>> [[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.
>>
>

[[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] Pass an equation as an argument of a sub-function

2019-06-06 Thread Bert Gunter
See here for almost the same issue:

http://r.789695.n4.nabble.com/Pasting-R-code-lines-into-labels-td4757446.html

Same answer: pass the unevaluated formula (i.e. an R expression) using
substitute/quote. Then evaluate it appropriately using eval. Same
references.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Jun 6, 2019 at 11:08 AM Frank S.  wrote:

> Dear all,
>
> I have defined an R function g(y) wich in turn is inside other R function
> f(x). The function g(y) depends on an
> equation, and I would like to know if such an equation could be passed as
> an argument of the main function
> (taking into account that we should change the variable "x" to "y").
> As an example, I have:
>
> function(x) { # Main function, called f(x)
>
>   -  (code)
>
>   function(y) {# Sub-function, called g(y)
> -  (code)
> eq <- y^2 -3*y
> - (code)
>   }
>
>   - (code)
>
> }
>
> In summary, I would like to know is there is any way to:
> Put the equation "eq" as an argument of the main function f(x).
>
>
> Thank you very much!
>
> Frank
>
> [[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.
>

[[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] Pasting R code lines into labels

2019-06-06 Thread Bert Gunter
Yes, plot(z,y,..)

Bert

On Thu, Jun 6, 2019 at 9:21 AM Nick Wray  wrote:

> Thanks Bert, that is exactly what I wanted.  I think that you meant
> plot(z,y... in the last line?
>
> Nick
>
> On 06 June 2019 at 17:13 Bert Gunter  wrote:
>
> ... and if you wanted too streamline the process, something like the
> following could be encapsulated in a function:
>
> fun <- quote(exp(x))
> z <- 1:9
> y <- eval(fun,list(x = z) )
> plot(x, y, main = paste("Plot of y =", deparse(fun)))
>
> Further details can be found in the "Computing on the Language" section of
> the "R Language Reference" manual or from suitable tutorials on the web.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, Jun 6, 2019 at 8:55 AM Nick Wray via R-help < r-help@r-project.org>
> wrote:
>
> Thanks but that's not quite what I meant
> I am trying out different functions and they don't necessarily vary in a
> regular way (like say all being powers of x where it'd be simple to just
> have a vector for the powers you want)
> So I might have
> y<-x^2
> y<-cos(x)
> y<-exp(x+1)
> What I am after is a way of running these functions and then calling each
> one into the labelling for the appropriate graph as I plot it.  So then I
> would have something like
> mainlab<-paste("Plot of ",function in question)
> ...? Thanks Nick
>
> > On 06 June 2019 at 16:40 Marc Schwartz < marc_schwa...@me.com> wrote:
> >
> >
> >
> > > On Jun 6, 2019, at 11:19 AM, Nick Wray via R-help <
> r-help@r-project.org> wrote:
> > >
> > > Is there any way of taking a line of r code (eg y<-x^2) and pasting
> that line of code, as is, into a label, so that for example I could then
> have a plot label "Plot of y<-x^2"?
> > >
> > > Thanks Nick Wray
> >
> >
> > Hi,
> >
> > See ?plotmath
> >
> > An example:
> >
> > x <- 1:10
> > y <- x^2
> >
> > plot(x, y, main = expression(paste("Plot of ", y %<-% x^2)))
> >
> >
> > There are other incantations and examples on the help page above.
> >
> > Regards,
> >
> > Marc Schwartz
> >
>
> __
> 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.


Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
Hi Rui,

NewestdataUltra looks like this (Note that "HistoricalMEDIAN" is hidden, but it 
follows "RCP8.5MEDIAN" listing the same way):



  x variable   value  L1
1   0.0y  0. onepctCO2MEDIAN
2   0.006794447y  4.90024902 onepctCO2MEDIAN
3   0.014288058y  0.1607 onepctCO2MEDIAN
4   0.022087920y  6.63491326 onepctCO2MEDIAN
5   0.030797357y -1.24295056 onepctCO2MEDIAN
6   0.038451072y  1.56433744 onepctCO2MEDIAN
7   0.048087904y -2.26590352 onepctCO2MEDIAN
8   0.058677729y  2.20700446 onepctCO2MEDIAN
9   0.069261406y -2.36770013 onepctCO2MEDIAN
10  0.080524530y -1.09135062 onepctCO2MEDIAN
11  0.092760246y  0.40999399 onepctCO2MEDIAN
12  0.103789609y -0.12597268 onepctCO2MEDIAN
13  0.116953168y -2.41382534 onepctCO2MEDIAN
14  0.129253298y  7.08902570 onepctCO2MEDIAN
15  0.141710050y -0.75935388 onepctCO2MEDIAN
16  0.156002052y  0.04544160 onepctCO2MEDIAN
17  0.170648172y -1.53496826 onepctCO2MEDIAN
18  0.185318425y  6.55242014 onepctCO2MEDIAN
19  0.199463055y -0.83125628 onepctCO2MEDIAN
20  0.213513337y -2.50991826 onepctCO2MEDIAN
21  0.228839271y  0.13659682 onepctCO2MEDIAN
22  0.246981293y -1.37198445 onepctCO2MEDIAN
23  0.263012767y -0.87129883 onepctCO2MEDIAN
24  0.278505564y  0.66325836 onepctCO2MEDIAN
25  0.293658361y  0.79380363 onepctCO2MEDIAN
26  0.310747266y  3.48806374 onepctCO2MEDIAN
27  0.325990349y -4.46122081 onepctCO2MEDIAN
28  0.342517540y  0.08717340 onepctCO2MEDIAN
29  0.362751633y -1.41715777 onepctCO2MEDIAN
30  0.380199537y -0.99565082 onepctCO2MEDIAN
31  0.394992948y  0.32155262 onepctCO2MEDIAN
32  0.414373398y  3.14038657 onepctCO2MEDIAN
33  0.430690214y -0.73760988 onepctCO2MEDIAN
34  0.449738145y -2.48605407 onepctCO2MEDIAN
35  0.470167458y -3.42358584 onepctCO2MEDIAN
36  0.489019871y  0.48247475 onepctCO2MEDIAN
37  0.507242471y -0.97853863 onepctCO2MEDIAN
38  0.524314284y  8.53596838 onepctCO2MEDIAN
39  0.543750525y  5.48447420 onepctCO2MEDIAN
40  0.564234197y  3.21493666 onepctCO2MEDIAN
41  0.583679616y  3.91689160 onepctCO2MEDIAN
42  0.601459444y  4.49070196 onepctCO2MEDIAN
43  0.619924664y  6.54104103 onepctCO2MEDIAN
44  0.639932007y  4.80686500 onepctCO2MEDIAN
45  0.661347181y  8.15101701 onepctCO2MEDIAN
46  0.684117317y  0.26974132 onepctCO2MEDIAN
47  0.704829752y -0.18075007 onepctCO2MEDIAN
48  0.725045770y  9.71812491 onepctCO2MEDIAN
49  0.745165825y  1.54064657 onepctCO2MEDIAN
50  0.765016139y -1.64760409 onepctCO2MEDIAN
51  0.783461511y  4.80246029 onepctCO2MEDIAN
52  0.806382924y  4.04215160 onepctCO2MEDIAN
53  0.829241335y  9.37565122 onepctCO2MEDIAN
54  0.849924415y  5.33050497 onepctCO2MEDIAN
55  0.871352434y  7.54458026 onepctCO2MEDIAN
56  0.893632233y  6.46795471 onepctCO2MEDIAN
57  0.916052133y  2.80960651 onepctCO2MEDIAN
58  0.938579470y  5.39216613 onepctCO2MEDIAN
59  0.959907651y  7.20436888 onepctCO2MEDIAN
60  0.981643587y  3.33508065 onepctCO2MEDIAN
61  1.004116774y  8.86907070 onepctCO2MEDIAN
62  1.028363466y  1.78612989 onepctCO2MEDIAN
63  1.054009140y  6.25550382 onepctCO2MEDIAN
64  1.072440803y  7.60792365 onepctCO2MEDIAN
65  1.094457805y  7.68714831 onepctCO2MEDIAN
66  1.123176277y  4.77877639 onepctCO2MEDIAN
67  1.149430871y 12.71105018 onepctCO2MEDIAN
68  1.170912921y -0.71562844 onepctCO2MEDIAN
69  1.196743071y  1.64908992 onepctCO2MEDIAN
70  1.218625903y  3.03630241 onepctCO2MEDIAN
71  1.241868377y  4.29747688 onepctCO2MEDIAN
72  1.267941594y  1.95437781 onepctCO2MEDIAN
73  1.290708780y  3.99869637 onepctCO2MEDIAN
74  1.31389y  4.51794725 onepctCO2MEDIAN
75  1.339045882y  0.93379048 onepctCO2MEDIAN
76  1.362803459y  3.30507700 onepctCO2MEDIAN
77  1.384450197y  3.54229702 onepctCO2MEDIAN
78  1.409720302y  5.99736597 onepctCO2MEDIAN
79  1.435851157y  0.50818686 onepctCO2MEDIAN
80  1.455592215y  7.96616301 onepctCO2MEDIAN
81  1.479495347y  9.94604963 onepctCO2MEDIAN
82  1.506051958y  3.79083717 onepctCO2MEDIAN
83  1.525728464y  2.57358469 onepctCO2MEDIAN
84  1.549362063y 10.14049742 onepctCO2MEDIAN
85  1.573440671y 13.74083036 onepctCO2MEDIAN
86  1.600278735y  0.93357712 onepctCO2MEDIAN
87  1.623879492y  9.75887417 onepctCO2MEDIAN
88  1.650029302y  1.27693947 onepctCO2MEDIAN
89  1.672362328y 13.49709060 onepctCO2MEDIAN
90  1.700221121y 10.20875018 onepctCO2MEDIAN
91  1.724793375y  1.68112753 

Re: [R] Open a file which name contains a tilde

2019-06-06 Thread Berry, Charles



> On Jun 6, 2019, at 3:59 AM, Ivan Krylov  wrote:
> 
> On Wed, 5 Jun 2019 18:07:15 +0200
> Frank Schwidom  wrote:
> 
>> +> path.expand("a ~ b")  
>> [1] "a /home/user b"
> 
>> How can I switch off any file crippling activity?
> 
> It doesn't seem to be possible if readline is enabled and works
> correctly.
> 
> Calls to path.expand [1] end up [2] in R_ExpandFileName [3], which
> calls R_ExpandFileName_readline [4], which uses libreadline function
> tilde_expand [5]. tilde_expand seems to be designed to expand '~'
> anywhere in the string it is handed, i.e. operate on whole command
> lines, not file paths.
> 

FWIW, the tilde does not always trigger this behavior. 

It seems that the tilde needs to be first in the string or preceded by 
whitespace and succeeded by whitespace or a path separator so the result looks 
like a path. 

> path.expand("~/abc/~/def")
[1] "/Users/cberry/abc/~/def"
> 

> path.expand("~/abc/ ~/def")
[1] "/Users/cberry/abc/ /Users/cberry/def"

> path.expand("~/abc/ ~tilde~/def")
[1] "/Users/cberry/abc/ ~tilde~/def"
> 
> path.expand("~/abc/ ~tilde ~/def")
[1] "/Users/cberry/abc/ ~tilde /Users/cberry/def"

An inelegant workaround could be built by adding escapes to the initial path 
and stripping them from the result.

Perhaps, the intent (in GNU deadline) was to allow a string with multiple paths 
separated by whitespace to be processed.

Maybe this is seen as a feature in GNU readline even though it is not helpful 
here.

HTH,

Chuck

__
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] Pasting R code lines into labels

2019-06-06 Thread Nick Wray via R-help
Thanks Bert, that is exactly what I wanted.  I think that you meant plot(z,y... 
in the last line?

Nick

> On 06 June 2019 at 17:13 Bert Gunter  wrote:
> 
> ... and if you wanted too streamline the process, something like the 
> following could be encapsulated in a function:
> 
> fun <- quote(exp(x))
> z <- 1:9
> y <- eval(fun,list(x = z) )
> plot(x, y, main = paste("Plot of y =", deparse(fun)))
> 
> Further details can be found in the "Computing on the Language" section 
> of the "R Language Reference" manual or from suitable tutorials on the web.
> 
> Bert Gunter
> 
> "The trouble with having an open mind is that people keep coming along 
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> 
> 
> On Thu, Jun 6, 2019 at 8:55 AM Nick Wray via R-help < 
> r-help@r-project.org mailto:r-help@r-project.org > wrote:
> 
> > > Thanks but that's not quite what I meant
> > I am trying out different functions and they don't necessarily vary 
> > in a regular way (like say all being powers of x where it'd be simple to 
> > just have a vector for the powers you want)
> > So I might have
> > y<-x^2
> > y<-cos(x)
> > y<-exp(x+1)
> > What I am after is a way of running these functions and then 
> > calling each one into the labelling for the appropriate graph as I plot it. 
> >  So then I would have something like
> > mainlab<-paste("Plot of ",function in question)
> > ...? Thanks Nick
> > 
> > > On 06 June 2019 at 16:40 Marc Schwartz < marc_schwa...@me.com 
> > mailto:marc_schwa...@me.com > wrote:
> > >
> > >
> > >
> > > > On Jun 6, 2019, at 11:19 AM, Nick Wray via R-help < 
> > r-help@r-project.org mailto:r-help@r-project.org > wrote:
> > > >
> > > > Is there any way of taking a line of r code (eg y<-x^2) and 
> > pasting that line of code, as is, into a label, so that for example I could 
> > then have a plot label "Plot of y<-x^2"?
> > > >
> > > > Thanks Nick Wray
> > >
> > >
> > > Hi,
> > >
> > > See ?plotmath
> > >
> > > An example:
> > >
> > > x <- 1:10
> > > y <- x^2
> > >
> > > plot(x, y, main = expression(paste("Plot of ", y %<-% x^2)))
> > >
> > >
> > > There are other incantations and examples on the help page above.
> > >
> > > Regards,
> > >
> > > Marc Schwartz
> > >
> > 
> > __
> > R-help@r-project.org mailto: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.


Re: [R] Pasting R code lines into labels

2019-06-06 Thread Bert Gunter
... and if you wanted too streamline the process, something like the
following could be encapsulated in a function:

fun <- quote(exp(x))
z <- 1:9
y <- eval(fun,list(x = z) )
plot(x, y, main = paste("Plot of y =", deparse(fun)))

Further details can be found in the "Computing on the Language" section of
the "R Language Reference" manual or from suitable tutorials on the web.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Jun 6, 2019 at 8:55 AM Nick Wray via R-help 
wrote:

> Thanks but that's not quite what I meant
> I am trying out different functions and they don't necessarily vary in a
> regular way (like say all being powers of x where it'd be simple to just
> have a vector for the powers you want)
> So I might have
> y<-x^2
> y<-cos(x)
> y<-exp(x+1)
> What I am after is a way of running these functions and then calling each
> one into the labelling for the appropriate graph as I plot it.  So then I
> would have something like
> mainlab<-paste("Plot of ",function in question)
> ...? Thanks Nick
>
> > On 06 June 2019 at 16:40 Marc Schwartz  wrote:
> >
> >
> >
> > > On Jun 6, 2019, at 11:19 AM, Nick Wray via R-help <
> r-help@r-project.org> wrote:
> > >
> > > Is there any way of taking a line of r code (eg y<-x^2) and pasting
> that line of code, as is, into a label, so that for example I could then
> have a plot label "Plot of y<-x^2"?
> > >
> > > Thanks Nick Wray
> >
> >
> > Hi,
> >
> > See ?plotmath
> >
> > An example:
> >
> > x <- 1:10
> > y <- x^2
> >
> > plot(x, y, main = expression(paste("Plot of ", y %<-% x^2)))
> >
> >
> > There are other incantations and examples on the help page above.
> >
> > Regards,
> >
> > Marc Schwartz
> >
>
> __
> 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.


Re: [R] Pasting R code lines into labels

2019-06-06 Thread Nick Wray via R-help
Thanks but that's not quite what I meant
I am trying out different functions and they don't necessarily vary in a 
regular way (like say all being powers of x where it'd be simple to just have a 
vector for the powers you want)
So I might have
y<-x^2
y<-cos(x)
y<-exp(x+1)
What I am after is a way of running these functions and then calling each one 
into the labelling for the appropriate graph as I plot it.  So then I would 
have something like
mainlab<-paste("Plot of ",function in question)
...? Thanks Nick

> On 06 June 2019 at 16:40 Marc Schwartz  wrote:
> 
> 
> 
> > On Jun 6, 2019, at 11:19 AM, Nick Wray via R-help  
> > wrote:
> > 
> > Is there any way of taking a line of r code (eg y<-x^2) and pasting that 
> > line of code, as is, into a label, so that for example I could then have a 
> > plot label "Plot of y<-x^2"?
> > 
> > Thanks Nick Wray 
> 
> 
> Hi,
> 
> See ?plotmath
> 
> An example:
> 
> x <- 1:10
> y <- x^2
> 
> plot(x, y, main = expression(paste("Plot of ", y %<-% x^2)))
> 
> 
> There are other incantations and examples on the help page above.
> 
> Regards,
> 
> Marc Schwartz
>

__
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] Pasting R code lines into labels

2019-06-06 Thread Bert Gunter
The well known deparse(substitute(...)) construction.

plot(1:9, main = paste("plot of",deparse(substitute(y <- x^2

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Jun 6, 2019 at 8:19 AM Nick Wray via R-help 
wrote:

> Is there any way of taking a line of r code (eg y<-x^2) and pasting that
> line of code, as is, into a label, so that for example I could then have a
> plot label "Plot of y<-x^2"?
>
> Thanks Nick Wray
> [[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.
>

[[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] Plotting more than one regression line in ggplot

2019-06-06 Thread Rui Barradas

Hello,

It's impossible to say without seeing the data.

What is the return value of

df_tmp <- subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN')
unique(df_tmp$L1)

The number of colors must be the same as

length(unique(df_tmp$L1))


Hope this helps,

Rui Barradas

Às 16:49 de 06/06/19, rain1...@aim.com escreveu:

Hi Rui,

Yes, you are right. It should be this, but I tried with only 3 colors, 
as you suggested:


ggplot(subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN'), aes(x, value, 
colour = L1)) + geom_point() + scale_color_manual(values =c("green", 
"blue" "red")) + geom_smooth(method = lm, se=FALSE)


**//___^
**//___^I still end up with the same error, however, when I specify only 
3 colors. Why could this be?



-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 11:18 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

1) In the text you say your dataset is named NewestdataUltra but in the
ggplot instruction it's Newestdata. One of these is wrong.

2) Is it onepctCO2MEDIAN or RCPonepctCO2MEDIAN?

3) You are filtering out the value in point ) above. So you only plot 3
regression lines, you don't need 4 colors.


Hope this helps,

Rui Barradas

Às 15:35 de 06/06/19, rain1...@aim.com  escreveu:
 > Hi Rui (and everyone),
 >
 >
 > Thank you for this! Yes, this did work fine, as I can see my scatter
 > plots and regression lines on the same plot, along with the appropriate
 > coloring scheme! :)
 >
 > Just one last question concerning this - I melted other dataframes into
 > my new "NewestdataUltra". I now have 4 objects listed in there in this
 > order (starting from the top of the list): "onepctCO2MEDIAN",
 > "RCP4.5MEDIAN", RCP8.5MEDIAN", and "HistoricalMEDIAN". I tried plotting
 > colored scattered plots and regression lines for these in this manner:
 >
 > ggplot(subset(Newestdata, L1 != 'RCPonepctCO2MEDIAN'), aes(x, value,
 > colour = L1)) + geom_point() + scale_color_manual(values =c("green",
 > "blue" "red", "black")) + geom_smooth(method = lm, se=FALSE)
 >
 > However, I received this error:
 >
 > Error: unexpected string constant in "ggplot(subset(NewestdataUltra, L1
 > != 'RCPonepctCO2MEDIAN'), aes(x, value, colour = L1)) + geom_point() +
 > scale_color_manual(values =c("green", "blue" "red""
 >
 > **//___^
 >
 > Why would this error appear?  I think that I assigned the colors
 > correctly to each of the four objects in question, so why would this 
occur?

 >
 > Thank you, once again!
 >
 > -Original Message-
 > From: Rui Barradas mailto:ruipbarra...@sapo.pt>>
 > To: rain1290 mailto:rain1...@aim.com>>; r-help 
mailto:r-help@R-project.org>>

 > Sent: Thu, Jun 6, 2019 6:52 am
 > Subject: Re: [R] Plotting more than one regression line in ggplot
 >
 > Hello,
 >
 > You are confusing some of the values of L1 with L1 itself.
 > If you just want two of those values in your plot, "onepctCO2MEDIAN" and
 > "RCP8.5MEDIAN", you need to subset the data filtering out the rows with
 > L1 == "RCP4.5MEDIAN".
 >
 > And please forget geom_jitter, it is completely inappropriate for the
 > type of scatter plot you are trying to graph. You jitter when there is
 > overplotting, not as a general purpose technique.
 >
 > Here is one way to do it.
 >
 >
 > ggplot(subset(NewestdataUltra, L1 != 'RCP4.5MEDIAN'),
 >          aes(x, value, colour = L1)) +
 >    geom_point() +
 >    scale_color_manual(values = c("green", "red")) +
 >    geom_smooth(method = lm)
 >
 >
 > Hope this helps,
 >
 > Rui Barradas
 >
 > Às 22:37 de 05/06/19, rain1...@aim.com  
> escreveu:

 >  > Hi Rui (and everyone),
 >  >
 >  > Thank you so much for your response! Much appreciated!
 >  >
 >  > What if I wanted I create several regression lines and scatter 
plots in

 >  > the same ggplot using a "melted" dataset? I would like to create a
 >  > scatter plot and regression line for both the objects of
 >  > "onepctCO2MEDIAN" and "RCP8.5MEDIANThis melted dataset looks like 
this:

 >  >
 >  >
 >  >  >NewestdataUltra
 >  >
 >  > x variable value L1 1 0.0 y 0. onepctCO2MEDIAN 2
 >  > 0.006794447 y 4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607
 >  > onepctCO2MEDIAN 4 0.022087920 y 6.63491326 onepctCO2MEDIAN 5 
0.030797357
 >  > y -1.24295056 onepctCO2MEDIAN 6 0.038451072 y 1.56433744 
onepctCO2MEDIAN

 >  > 7 0.048087904 y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y 2.20700446
 >  > onepctCO2MEDIAN 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10
 >  > 0.080524530 y -1.09135062 onepctCO2MEDIAN 11 0.092760246 y 0.40999399
 >  > onepctCO2MEDIAN 12 0.103789609 y -0.12597268 onepctCO2MEDIAN 13
 >  > 0.116953168 y -2.41382534 onepctCO2MEDIAN 14 0.129253298 y 7.08902570
 >  > onepctCO2MEDIAN 15 0.141710050 y -0.75935388 onepctCO2MEDIAN 16
 >  > 0.156002052 y 0.04544160 onepctCO2MEDIAN 17 0.170648172 y -1.53496826
 >  > onepctCO2MEDIAN 18 0.185318425 y 6.55242014 

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
Hi Rui,

Yes, you are right. It should be this, but I tried with only 3 colors, as you 
suggested:
ggplot(subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN'), aes(x, value, colour = 
L1)) + geom_point() + scale_color_manual(values =c("green", "blue" "red")) + 
geom_smooth(method = lm, se=FALSE)
I still end up with the same error, however, when I specify only 3 colors. Why 
could this be?

-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 11:18 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

1) In the text you say your dataset is named NewestdataUltra but in the 
ggplot instruction it's Newestdata. One of these is wrong.

2) Is it onepctCO2MEDIAN or RCPonepctCO2MEDIAN?

3) You are filtering out the value in point ) above. So you only plot 3 
regression lines, you don't need 4 colors.


Hope this helps,

Rui Barradas

Às 15:35 de 06/06/19, rain1...@aim.com escreveu:
> Hi Rui (and everyone),
> 
> 
> Thank you for this! Yes, this did work fine, as I can see my scatter 
> plots and regression lines on the same plot, along with the appropriate 
> coloring scheme! :)
> 
> Just one last question concerning this - I melted other dataframes into 
> my new "NewestdataUltra". I now have 4 objects listed in there in this 
> order (starting from the top of the list): "onepctCO2MEDIAN", 
> "RCP4.5MEDIAN", RCP8.5MEDIAN", and "HistoricalMEDIAN". I tried plotting 
> colored scattered plots and regression lines for these in this manner:
> 
> ggplot(subset(Newestdata, L1 != 'RCPonepctCO2MEDIAN'), aes(x, value, 
> colour = L1)) + geom_point() + scale_color_manual(values =c("green", 
> "blue" "red", "black")) + geom_smooth(method = lm, se=FALSE)
> 
> However, I received this error:
> 
> Error: unexpected string constant in "ggplot(subset(NewestdataUltra, L1 
> != 'RCPonepctCO2MEDIAN'), aes(x, value, colour = L1)) + geom_point() + 
> scale_color_manual(values =c("green", "blue" "red""
> 
> **//___^
> 
> Why would this error appear?  I think that I assigned the colors 
> correctly to each of the four objects in question, so why would this occur?
> 
> Thank you, once again!
> 
> -Original Message-
> From: Rui Barradas 
> To: rain1290 ; r-help 
> Sent: Thu, Jun 6, 2019 6:52 am
> Subject: Re: [R] Plotting more than one regression line in ggplot
> 
> Hello,
> 
> You are confusing some of the values of L1 with L1 itself.
> If you just want two of those values in your plot, "onepctCO2MEDIAN" and
> "RCP8.5MEDIAN", you need to subset the data filtering out the rows with
> L1 == "RCP4.5MEDIAN".
> 
> And please forget geom_jitter, it is completely inappropriate for the
> type of scatter plot you are trying to graph. You jitter when there is
> overplotting, not as a general purpose technique.
> 
> Here is one way to do it.
> 
> 
> ggplot(subset(NewestdataUltra, L1 != 'RCP4.5MEDIAN'),
>          aes(x, value, colour = L1)) +
>    geom_point() +
>    scale_color_manual(values = c("green", "red")) +
>    geom_smooth(method = lm)
> 
> 
> Hope this helps,
> 
> Rui Barradas
> 
> Às 22:37 de 05/06/19, rain1...@aim.com  escreveu:
>  > Hi Rui (and everyone),
>  >
>  > Thank you so much for your response! Much appreciated!
>  >
>  > What if I wanted I create several regression lines and scatter plots in
>  > the same ggplot using a "melted" dataset? I would like to create a
>  > scatter plot and regression line for both the objects of
>  > "onepctCO2MEDIAN" and "RCP8.5MEDIANThis melted dataset looks like this:
>  >
>  >
>  >  >NewestdataUltra
>  >
>  > x variable value L1 1 0.0 y 0. onepctCO2MEDIAN 2
>  > 0.006794447 y 4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607
>  > onepctCO2MEDIAN 4 0.022087920 y 6.63491326 onepctCO2MEDIAN 5 0.030797357
>  > y -1.24295056 onepctCO2MEDIAN 6 0.038451072 y 1.56433744 onepctCO2MEDIAN
>  > 7 0.048087904 y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y 2.20700446
>  > onepctCO2MEDIAN 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10
>  > 0.080524530 y -1.09135062 onepctCO2MEDIAN 11 0.092760246 y 0.40999399
>  > onepctCO2MEDIAN 12 0.103789609 y -0.12597268 onepctCO2MEDIAN 13
>  > 0.116953168 y -2.41382534 onepctCO2MEDIAN 14 0.129253298 y 7.08902570
>  > onepctCO2MEDIAN 15 0.141710050 y -0.75935388 onepctCO2MEDIAN 16
>  > 0.156002052 y 0.04544160 onepctCO2MEDIAN 17 0.170648172 y -1.53496826
>  > onepctCO2MEDIAN 18 0.185318425 y 6.55242014 onepctCO2MEDIAN 19
>  > 0.199463055 y -0.83125628 onepctCO2MEDIAN 20 0.213513337 y -2.50991826
>  > onepctCO2MEDIAN 21 0.228839271 y 0.13659682 onepctCO2MEDIAN 22
>  > 0.246981293 y -1.37198445 onepctCO2MEDIAN 23 0.263012767 y -0.87129883
>  > onepctCO2MEDIAN 24 0.278505564 y 0.66325836 onepctCO2MEDIAN 25
>  > 0.293658361 y 0.79380363 onepctCO2MEDIAN 26 0.310747266 y 3.48806374
>  > onepctCO2MEDIAN 27 0.325990349 y -4.46122081 onepctCO2MEDIAN 28
>  > 0.342517540 y 0.08717340 onepctCO2MEDIAN 29 0.362751633 y -1.41715777
>  > onepctCO2MEDIAN 30 0.380199537 y 

Re: [R] Pasting R code lines into labels

2019-06-06 Thread Marc Schwartz via R-help


> On Jun 6, 2019, at 11:19 AM, Nick Wray via R-help  
> wrote:
> 
> Is there any way of taking a line of r code (eg y<-x^2) and pasting that line 
> of code, as is, into a label, so that for example I could then have a plot 
> label "Plot of y<-x^2"?
> 
> Thanks Nick Wray 


Hi,

See ?plotmath

An example:

x <- 1:10
y <- x^2

plot(x, y, main = expression(paste("Plot of ", y %<-% x^2)))


There are other incantations and examples on the help page above.

Regards,

Marc Schwartz

__
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] Plotting more than one regression line in ggplot

2019-06-06 Thread Rui Barradas

Hello,

1) In the text you say your dataset is named NewestdataUltra but in the 
ggplot instruction it's Newestdata. One of these is wrong.


2) Is it onepctCO2MEDIAN or RCPonepctCO2MEDIAN?

3) You are filtering out the value in point ) above. So you only plot 3 
regression lines, you don't need 4 colors.



Hope this helps,

Rui Barradas

Às 15:35 de 06/06/19, rain1...@aim.com escreveu:

Hi Rui (and everyone),


Thank you for this! Yes, this did work fine, as I can see my scatter 
plots and regression lines on the same plot, along with the appropriate 
coloring scheme! :)


Just one last question concerning this - I melted other dataframes into 
my new "NewestdataUltra". I now have 4 objects listed in there in this 
order (starting from the top of the list): "onepctCO2MEDIAN", 
"RCP4.5MEDIAN", RCP8.5MEDIAN", and "HistoricalMEDIAN". I tried plotting 
colored scattered plots and regression lines for these in this manner:


ggplot(subset(Newestdata, L1 != 'RCPonepctCO2MEDIAN'), aes(x, value, 
colour = L1)) + geom_point() + scale_color_manual(values =c("green", 
"blue" "red", "black")) + geom_smooth(method = lm, se=FALSE)


However, I received this error:

Error: unexpected string constant in "ggplot(subset(NewestdataUltra, L1 
!= 'RCPonepctCO2MEDIAN'), aes(x, value, colour = L1)) + geom_point() + 
scale_color_manual(values =c("green", "blue" "red""


**//___^

Why would this error appear?  I think that I assigned the colors 
correctly to each of the four objects in question, so why would this occur?


Thank you, once again!

-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 6:52 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

You are confusing some of the values of L1 with L1 itself.
If you just want two of those values in your plot, "onepctCO2MEDIAN" and
"RCP8.5MEDIAN", you need to subset the data filtering out the rows with
L1 == "RCP4.5MEDIAN".

And please forget geom_jitter, it is completely inappropriate for the
type of scatter plot you are trying to graph. You jitter when there is
overplotting, not as a general purpose technique.

Here is one way to do it.


ggplot(subset(NewestdataUltra, L1 != 'RCP4.5MEDIAN'),
         aes(x, value, colour = L1)) +
   geom_point() +
   scale_color_manual(values = c("green", "red")) +
   geom_smooth(method = lm)


Hope this helps,

Rui Barradas

Às 22:37 de 05/06/19, rain1...@aim.com  escreveu:
 > Hi Rui (and everyone),
 >
 > Thank you so much for your response! Much appreciated!
 >
 > What if I wanted I create several regression lines and scatter plots in
 > the same ggplot using a "melted" dataset? I would like to create a
 > scatter plot and regression line for both the objects of
 > "onepctCO2MEDIAN" and "RCP8.5MEDIANThis melted dataset looks like this:
 >
 >
 >  >NewestdataUltra
 >
 > x variable value L1 1 0.0 y 0. onepctCO2MEDIAN 2
 > 0.006794447 y 4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607
 > onepctCO2MEDIAN 4 0.022087920 y 6.63491326 onepctCO2MEDIAN 5 0.030797357
 > y -1.24295056 onepctCO2MEDIAN 6 0.038451072 y 1.56433744 onepctCO2MEDIAN
 > 7 0.048087904 y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y 2.20700446
 > onepctCO2MEDIAN 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10
 > 0.080524530 y -1.09135062 onepctCO2MEDIAN 11 0.092760246 y 0.40999399
 > onepctCO2MEDIAN 12 0.103789609 y -0.12597268 onepctCO2MEDIAN 13
 > 0.116953168 y -2.41382534 onepctCO2MEDIAN 14 0.129253298 y 7.08902570
 > onepctCO2MEDIAN 15 0.141710050 y -0.75935388 onepctCO2MEDIAN 16
 > 0.156002052 y 0.04544160 onepctCO2MEDIAN 17 0.170648172 y -1.53496826
 > onepctCO2MEDIAN 18 0.185318425 y 6.55242014 onepctCO2MEDIAN 19
 > 0.199463055 y -0.83125628 onepctCO2MEDIAN 20 0.213513337 y -2.50991826
 > onepctCO2MEDIAN 21 0.228839271 y 0.13659682 onepctCO2MEDIAN 22
 > 0.246981293 y -1.37198445 onepctCO2MEDIAN 23 0.263012767 y -0.87129883
 > onepctCO2MEDIAN 24 0.278505564 y 0.66325836 onepctCO2MEDIAN 25
 > 0.293658361 y 0.79380363 onepctCO2MEDIAN 26 0.310747266 y 3.48806374
 > onepctCO2MEDIAN 27 0.325990349 y -4.46122081 onepctCO2MEDIAN 28
 > 0.342517540 y 0.08717340 onepctCO2MEDIAN 29 0.362751633 y -1.41715777
 > onepctCO2MEDIAN 30 0.380199537 y -0.99565082 onepctCO2MEDIAN 31
 > 0.394992948 y 0.32155262 onepctCO2MEDIAN 32 0.414373398 y 3.14038657
 > onepctCO2MEDIAN 33 0.430690214 y -0.73760988 onepctCO2MEDIAN 34
 > 0.449738145 y -2.48605407 onepctCO2MEDIAN 35 0.470167458 y -3.42358584
 > onepctCO2MEDIAN 36 0.489019871 y 0.48247475 onepctCO2MEDIAN 37
 > 0.507242471 y -0.97853863 onepctCO2MEDIAN 38 0.524314284 y 8.53596838
 > onepctCO2MEDIAN 39 0.543750525 y 5.48447420 onepctCO2MEDIAN 40
 > 0.564234197 y 3.21493666 onepctCO2MEDIAN 41 0.583679616 y 3.91689160
 > onepctCO2MEDIAN 42 0.601459444 y 4.49070196 onepctCO2MEDIAN 43
 > 0.619924664 y 6.54104103 onepctCO2MEDIAN 44 0.639932007 y 4.80686500
 > onepctCO2MEDIAN 45 0.661347181 y 8.15101701 onepctCO2MEDIAN 46
 > 0.684117317 y 

[R] Pasting R code lines into labels

2019-06-06 Thread Nick Wray via R-help
Is there any way of taking a line of r code (eg y<-x^2) and pasting that line 
of code, as is, into a label, so that for example I could then have a plot 
label "Plot of y<-x^2"?

Thanks Nick Wray 
[[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] Plotting more than one regression line in ggplot

2019-06-06 Thread PIKAL Petr
Hi

Probably missing quotation marks in geom_smooth

geom_smooth(method = "lm", se = FALSE)

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of rain1290--- via R-
> help
> Sent: Thursday, June 6, 2019 4:35 PM
> To: ruipbarra...@sapo.pt; r-help@R-project.org
> Subject: Re: [R] Plotting more than one regression line in ggplot
>
> Hi Rui (and everyone),
> Thank you for this! Yes, this did work fine, as I can see my scatter plots and
> regression lines on the same plot, along with the appropriate coloring scheme!
> :)
> Just one last question concerning this - I melted other dataframes into my new
> "NewestdataUltra". I now have 4 objects listed in there in this order 
> (starting
> from the top of the list): "onepctCO2MEDIAN", "RCP4.5MEDIAN",
> RCP8.5MEDIAN", and "HistoricalMEDIAN". I tried plotting colored scattered
> plots and regression lines for these in this manner:
> ggplot(subset(Newestdata, L1 != 'RCPonepctCO2MEDIAN'), aes(x, value, colour
> = L1)) + geom_point() + scale_color_manual(values =c("green", "blue" "red",
> "black")) + geom_smooth(method = lm, se=FALSE) However, I received this
> error:
> Error: unexpected string constant in "ggplot(subset(NewestdataUltra, L1 !=
> 'RCPonepctCO2MEDIAN'), aes(x, value, colour = L1)) + geom_point() +
> scale_color_manual(values =c("green", "blue" "red""
>
> Why would this error appear?  I think that I assigned the colors correctly to
> each of the four objects in question, so why would this occur?
> Thank you, once again!
> -Original Message-
> From: Rui Barradas 
> To: rain1290 ; r-help 
> Sent: Thu, Jun 6, 2019 6:52 am
> Subject: Re: [R] Plotting more than one regression line in ggplot
>
> Hello,
>
> You are confusing some of the values of L1 with L1 itself.
> If you just want two of those values in your plot, "onepctCO2MEDIAN" and
> "RCP8.5MEDIAN", you need to subset the data filtering out the rows with
> L1 == "RCP4.5MEDIAN".
>
> And please forget geom_jitter, it is completely inappropriate for the
> type of scatter plot you are trying to graph. You jitter when there is
> overplotting, not as a general purpose technique.
>
> Here is one way to do it.
>
>
> ggplot(subset(NewestdataUltra, L1 != 'RCP4.5MEDIAN'),
> aes(x, value, colour = L1)) +
>   geom_point() +
>   scale_color_manual(values = c("green", "red")) +
>   geom_smooth(method = lm)
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 22:37 de 05/06/19, rain1...@aim.com escreveu:
> > Hi Rui (and everyone),
> >
> > Thank you so much for your response! Much appreciated!
> >
> > What if I wanted I create several regression lines and scatter plots in
> > the same ggplot using a "melted" dataset? I would like to create a
> > scatter plot and regression line for both the objects of
> > "onepctCO2MEDIAN" and "RCP8.5MEDIANThis melted dataset looks like
> this:
> >
> >
> >  >NewestdataUltra
> >
> > x variable value L1 1 0.0 y 0. onepctCO2MEDIAN 2
> > 0.006794447 y 4.90024902 onepctCO2MEDIAN 3 0.014288058 y
> 0.1607
> > onepctCO2MEDIAN 4 0.022087920 y 6.63491326 onepctCO2MEDIAN 5
> 0.030797357
> > y -1.24295056 onepctCO2MEDIAN 6 0.038451072 y 1.56433744
> onepctCO2MEDIAN
> > 7 0.048087904 y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y
> 2.20700446
> > onepctCO2MEDIAN 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10
> > 0.080524530 y -1.09135062 onepctCO2MEDIAN 11 0.092760246 y
> 0.40999399
> > onepctCO2MEDIAN 12 0.103789609 y -0.12597268 onepctCO2MEDIAN 13
> > 0.116953168 y -2.41382534 onepctCO2MEDIAN 14 0.129253298 y
> 7.08902570
> > onepctCO2MEDIAN 15 0.141710050 y -0.75935388 onepctCO2MEDIAN 16
> > 0.156002052 y 0.04544160 onepctCO2MEDIAN 17 0.170648172 y -
> 1.53496826
> > onepctCO2MEDIAN 18 0.185318425 y 6.55242014 onepctCO2MEDIAN 19
> > 0.199463055 y -0.83125628 onepctCO2MEDIAN 20 0.213513337 y -
> 2.50991826
> > onepctCO2MEDIAN 21 0.228839271 y 0.13659682 onepctCO2MEDIAN 22
> > 0.246981293 y -1.37198445 onepctCO2MEDIAN 23 0.263012767 y -
> 0.87129883
> > onepctCO2MEDIAN 24 0.278505564 y 0.66325836 onepctCO2MEDIAN 25
> > 0.293658361 y 0.79380363 onepctCO2MEDIAN 26 0.310747266 y
> 3.48806374
> > onepctCO2MEDIAN 27 0.325990349 y -4.46122081 onepctCO2MEDIAN 28
> > 0.342517540 y 0.08717340 onepctCO2MEDIAN 29 0.362751633 y -
> 1.41715777
> > onepctCO2MEDIAN 30 0.380199537 y -0.99565082 onepctCO2MEDIAN 31
> > 0.394992948 y 0.32155262 onepctCO2MEDIAN 32 0.414373398 y
> 3.14038657
> > onepctCO2MEDIAN 33 0.430690214 y -0.73760988 onepctCO2MEDIAN 34
> > 0.449738145 y -2.48605407 onepctCO2MEDIAN 35 0.470167458 y -
> 3.42358584
> > onepctCO2MEDIAN 36 0.489019871 y 0.48247475 onepctCO2MEDIAN 37
> > 0.507242471 y -0.97853863 onepctCO2MEDIAN 38 0.524314284 y
> 8.53596838
> > onepctCO2MEDIAN 39 0.543750525 y 5.48447420 onepctCO2MEDIAN 40
> > 0.564234197 y 3.21493666 onepctCO2MEDIAN 41 0.583679616 y
> 3.91689160
> > onepctCO2MEDIAN 42 0.601459444 y 4.49070196 onepctCO2MEDIAN 43
> > 0.619924664 y 6.54104103 onepctCO2MEDIAN 44 0.639932007 y
> 4.80686500
> > onepctCO2MEDIAN 

Re: [R] debug only top level function

2019-06-06 Thread Martin Maechler
> Duncan Murdoch 
> on Thu, 6 Jun 2019 07:38:40 -0400 writes:

> On 06/06/2019 6:00 a.m., PIKAL Petr wrote:
>> Thanks Duncan.
>> 
>> I think you found it. I have an object called s within my function. I 
wanted to check it, so I hit "s". This did not bring the object but instead it 
change behaviour of debug function. I did not find this in help pages nor in R 
exts or R intro manual. Maybe it would be worth considering to add something 
about it to debug help page.

> It's in the ?browser help page, which is linked from ?debug.

> Duncan Murdoch

Indeed.
As it is not the first time, users did not "find" this, I have
made the links a bit more visible (for future R versions), now.

I'd  use  '(s)'  instead of 's'  [and more often and
importantly, I have a variable 'n' somewhere and need to use
'(n)'  very regularly.

For smallish situations, btw, the use of   ls.str()  comes very handy.

It has to be noted that unfortunately, the difference between
'n' and 's' and 'c'  has been a bit "blurred" for byte compiled
functions, and as the default JIT level is high, I had
occasionallz wanted an easy way to revert the byte compilation
before debugging or another way to get rid of this
drawback..

Martin



>> 
>> Best regards
>> Petr
>> 
>>> -Original Message-
>>> From: Duncan Murdoch 
>>> Sent: Thursday, June 6, 2019 11:11 AM
>>> To: PIKAL Petr ; r-help@r-project.org
>>> Subject: Re: [R] debug only top level function
>>> 
>>> On 06/06/2019 4:55 a.m., PIKAL Petr wrote:
 Dear all
 
 I have a question about debug function. I did not use it for long time 
but my
>>> vague memory tell me, that when I used  debug(myfunction) in past, only
>>> myfunction was debugged and browser ignored any embedded function.
 
 example (simple)
 
 fff <- function(x) mean(x, na.rm=T)
 
 when I issue
> debug(fff)
> fff(1:10)
 debugging in: fff(1:10)
 debug at #1: mean(x, na.rm = T)
 Browse[2]>
 debugging in: mean(x, na.rm = T)
 debug: UseMethod("mean")
 Browse[3]>
 debugging in: mean.default(x, na.rm = T) ...
 it starts debugging mean function. I understand that it is indicated by
>>> Browse[n] but it could be quite messy if I have many embedded functions 
and
>>> difficult to follow.
 
 Can I persuade debug function not to bother with embedded functions 
(e.g.
>>> mean, median, mad, ...) and debug only my top level code?
>>> 
>>> There are several commands available.  Type "help" to see them:
>>> 
>>> n  next
>>> s  step into
>>> f  finish
>>> c or cont  continue
>>> Q  quit
>>> where  show stack
>>> help   show help
>>>  evaluate expression
>>> 
>>> 
>>> You want "n", and are getting "s".  I believe if you hit Enter without 
choosing
>>> one, it will do the same as the previous time, so you've probably used 
"s"
>>> sometime in the past.
>>> 
>>> Duncan Murdoch
>>> 
 
 Best regards
 Petr
 
> sessionInfo()
 R Under development (unstable) (2018-03-07 r74369)
 Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10
 x64 (build 17763)
 
 Matrix products: default
 
 locale:
 [1] LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250 [3]
 LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C [5]
 LC_TIME=Czech_Czechia.1250
 
 attached base packages:
 [1] stats datasets  utils grDevices graphics  methods   base
 
 other attached packages:
 [1] MASS_7.3-49 readxl_1.0.0lattice_0.20-35 fun_0.1
 
 loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16 cellranger_1.1.0 grid_3.5.0   plyr_1.8.4
 [5] gtable_0.2.0 scales_0.5.0 ggplot2_2.2.1pillar_1.2.1
 [9] rlang_0.2.0  lazyeval_0.2.1   rpart_4.1-13 tools_3.5.0
 [13] munsell_0.4.3compiler_3.5.0   colorspace_1.3-2 tibble_1.4.2

__
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] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
Hi Rui (and everyone),
Thank you for this! Yes, this did work fine, as I can see my scatter plots and 
regression lines on the same plot, along with the appropriate coloring scheme! 
:)
Just one last question concerning this - I melted other dataframes into my new 
"NewestdataUltra". I now have 4 objects listed in there in this order (starting 
from the top of the list): "onepctCO2MEDIAN", "RCP4.5MEDIAN", RCP8.5MEDIAN", 
and "HistoricalMEDIAN". I tried plotting colored scattered plots and regression 
lines for these in this manner:
ggplot(subset(Newestdata, L1 != 'RCPonepctCO2MEDIAN'), aes(x, value, colour = 
L1)) + geom_point() + scale_color_manual(values =c("green", "blue" "red", 
"black")) + geom_smooth(method = lm, se=FALSE) However, I received this error:
Error: unexpected string constant in "ggplot(subset(NewestdataUltra, L1 != 
'RCPonepctCO2MEDIAN'), aes(x, value, colour = L1)) + geom_point() + 
scale_color_manual(values =c("green", "blue" "red""

Why would this error appear?  I think that I assigned the colors correctly to 
each of the four objects in question, so why would this occur? 
Thank you, once again! 
-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 6:52 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

You are confusing some of the values of L1 with L1 itself.
If you just want two of those values in your plot, "onepctCO2MEDIAN" and 
"RCP8.5MEDIAN", you need to subset the data filtering out the rows with 
L1 == "RCP4.5MEDIAN".

And please forget geom_jitter, it is completely inappropriate for the 
type of scatter plot you are trying to graph. You jitter when there is 
overplotting, not as a general purpose technique.

Here is one way to do it.


ggplot(subset(NewestdataUltra, L1 != 'RCP4.5MEDIAN'),
        aes(x, value, colour = L1)) +
  geom_point() +
  scale_color_manual(values = c("green", "red")) +
  geom_smooth(method = lm)


Hope this helps,

Rui Barradas

Às 22:37 de 05/06/19, rain1...@aim.com escreveu:
> Hi Rui (and everyone),
> 
> Thank you so much for your response! Much appreciated!
> 
> What if I wanted I create several regression lines and scatter plots in 
> the same ggplot using a "melted" dataset? I would like to create a 
> scatter plot and regression line for both the objects of 
> "onepctCO2MEDIAN" and "RCP8.5MEDIANThis melted dataset looks like this:
> 
> 
>  >NewestdataUltra
> 
> x variable value L1 1 0.0 y 0. onepctCO2MEDIAN 2 
> 0.006794447 y 4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607 
> onepctCO2MEDIAN 4 0.022087920 y 6.63491326 onepctCO2MEDIAN 5 0.030797357 
> y -1.24295056 onepctCO2MEDIAN 6 0.038451072 y 1.56433744 onepctCO2MEDIAN 
> 7 0.048087904 y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y 2.20700446 
> onepctCO2MEDIAN 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10 
> 0.080524530 y -1.09135062 onepctCO2MEDIAN 11 0.092760246 y 0.40999399 
> onepctCO2MEDIAN 12 0.103789609 y -0.12597268 onepctCO2MEDIAN 13 
> 0.116953168 y -2.41382534 onepctCO2MEDIAN 14 0.129253298 y 7.08902570 
> onepctCO2MEDIAN 15 0.141710050 y -0.75935388 onepctCO2MEDIAN 16 
> 0.156002052 y 0.04544160 onepctCO2MEDIAN 17 0.170648172 y -1.53496826 
> onepctCO2MEDIAN 18 0.185318425 y 6.55242014 onepctCO2MEDIAN 19 
> 0.199463055 y -0.83125628 onepctCO2MEDIAN 20 0.213513337 y -2.50991826 
> onepctCO2MEDIAN 21 0.228839271 y 0.13659682 onepctCO2MEDIAN 22 
> 0.246981293 y -1.37198445 onepctCO2MEDIAN 23 0.263012767 y -0.87129883 
> onepctCO2MEDIAN 24 0.278505564 y 0.66325836 onepctCO2MEDIAN 25 
> 0.293658361 y 0.79380363 onepctCO2MEDIAN 26 0.310747266 y 3.48806374 
> onepctCO2MEDIAN 27 0.325990349 y -4.46122081 onepctCO2MEDIAN 28 
> 0.342517540 y 0.08717340 onepctCO2MEDIAN 29 0.362751633 y -1.41715777 
> onepctCO2MEDIAN 30 0.380199537 y -0.99565082 onepctCO2MEDIAN 31 
> 0.394992948 y 0.32155262 onepctCO2MEDIAN 32 0.414373398 y 3.14038657 
> onepctCO2MEDIAN 33 0.430690214 y -0.73760988 onepctCO2MEDIAN 34 
> 0.449738145 y -2.48605407 onepctCO2MEDIAN 35 0.470167458 y -3.42358584 
> onepctCO2MEDIAN 36 0.489019871 y 0.48247475 onepctCO2MEDIAN 37 
> 0.507242471 y -0.97853863 onepctCO2MEDIAN 38 0.524314284 y 8.53596838 
> onepctCO2MEDIAN 39 0.543750525 y 5.48447420 onepctCO2MEDIAN 40 
> 0.564234197 y 3.21493666 onepctCO2MEDIAN 41 0.583679616 y 3.91689160 
> onepctCO2MEDIAN 42 0.601459444 y 4.49070196 onepctCO2MEDIAN 43 
> 0.619924664 y 6.54104103 onepctCO2MEDIAN 44 0.639932007 y 4.80686500 
> onepctCO2MEDIAN 45 0.661347181 y 8.15101701 onepctCO2MEDIAN 46 
> 0.684117317 y 0.26974132 onepctCO2MEDIAN 47 0.704829752 y -0.18075007 
> onepctCO2MEDIAN 48 0.725045770 y 9.71812491 onepctCO2MEDIAN 49 
> 0.745165825 y 1.54064657 onepctCO2MEDIAN 50 0.765016139 y -1.64760409 
> onepctCO2MEDIAN 51 0.783461511 y 4.80246029 onepctCO2MEDIAN 52 
> 0.806382924 y 4.04215160 onepctCO2MEDIAN 53 0.829241335 y 9.37565122 
> onepctCO2MEDIAN 54 0.849924415 y 5.33050497 onepctCO2MEDIAN 55 
> 0.871352434 y 7.54458026 onepctCO2MEDIAN 56 

Re: [R] debug only top level function

2019-06-06 Thread Duncan Murdoch

On 06/06/2019 6:00 a.m., PIKAL Petr wrote:

Thanks Duncan.

I think you found it. I have an object called s within my function. I wanted to check it, 
so I hit "s". This did not bring the object but instead it change behaviour of 
debug function. I did not find this in help pages nor in R exts or R intro manual. Maybe 
it would be worth considering to add something about it to debug help page.


It's in the ?browser help page, which is linked from ?debug.

Duncan Murdoch



Best regards
Petr


-Original Message-
From: Duncan Murdoch 
Sent: Thursday, June 6, 2019 11:11 AM
To: PIKAL Petr ; r-help@r-project.org
Subject: Re: [R] debug only top level function

On 06/06/2019 4:55 a.m., PIKAL Petr wrote:

Dear all

I have a question about debug function. I did not use it for long time but my

vague memory tell me, that when I used  debug(myfunction) in past, only
myfunction was debugged and browser ignored any embedded function.


example (simple)

fff <- function(x) mean(x, na.rm=T)

when I issue

debug(fff)
fff(1:10)

debugging in: fff(1:10)
debug at #1: mean(x, na.rm = T)
Browse[2]>
debugging in: mean(x, na.rm = T)
debug: UseMethod("mean")
Browse[3]>
debugging in: mean.default(x, na.rm = T) ...
it starts debugging mean function. I understand that it is indicated by

Browse[n] but it could be quite messy if I have many embedded functions and
difficult to follow.


Can I persuade debug function not to bother with embedded functions (e.g.

mean, median, mad, ...) and debug only my top level code?

There are several commands available.  Type "help" to see them:

n  next
s  step into
f  finish
c or cont  continue
Q  quit
where  show stack
help   show help
 evaluate expression


You want "n", and are getting "s".  I believe if you hit Enter without choosing
one, it will do the same as the previous time, so you've probably used "s"
sometime in the past.

Duncan Murdoch



Best regards
Petr


sessionInfo()

R Under development (unstable) (2018-03-07 r74369)
Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10
x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250 [3]
LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C [5]
LC_TIME=Czech_Czechia.1250

attached base packages:
[1] stats datasets  utils grDevices graphics  methods   base

other attached packages:
[1] MASS_7.3-49 readxl_1.0.0lattice_0.20-35 fun_0.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 cellranger_1.1.0 grid_3.5.0   plyr_1.8.4
   [5] gtable_0.2.0 scales_0.5.0 ggplot2_2.2.1pillar_1.2.1
   [9] rlang_0.2.0  lazyeval_0.2.1   rpart_4.1-13 tools_3.5.0
[13] munsell_0.4.3compiler_3.5.0   colorspace_1.3-2 tibble_1.4.2



__
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.



Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/



__
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] Parallel processes collapse into one

2019-06-06 Thread Ivan Krylov
On Mon, 3 Jun 2019 06:37:46 +0200
Nicola Lunardon  wrote:

> R seems to be running, but simulations do not progress further.

Have you tried message() (or REprintf() in C code) to narrow down the
specific part of the code where simulations stop in their progress?
It's less convenient than a good debugger, but with parallel code it is
sometimes the only way to reproduce the problem and get some
information about it.

> If I run simulations on 16 cores I end up having an R instance with
> CPU usage about 1600%, never experienced such a behaviour.

> BLAS:   /usr/lib/openblas-base/libblas.so.3
> LAPACK: /usr/lib/libopenblasp-r0.2.18.so

OpenBLAS can, indeed, use multiple threads on its own, inside a single
process. Combined with mclapply, this might create a situation when
there are far more threads competing for CPU time than CPU cores
available. Does it help if you set an environment variable such as
OPENBLAS_NUM_THREADS [*] to a number less than or equal to (number of
CPU cores / mc.cores mclapply argument)?

-- 
Best regards,
Ivan

[*]
https://github.com/xianyi/OpenBLAS#setting-the-number-of-threads-using-environment-variables

__
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] Open a file which name contains a tilde

2019-06-06 Thread Ivan Krylov
On Wed, 5 Jun 2019 18:07:15 +0200
Frank Schwidom  wrote:

> +> path.expand("a ~ b")  
> [1] "a /home/user b"

> How can I switch off any file crippling activity?

It doesn't seem to be possible if readline is enabled and works
correctly.

Calls to path.expand [1] end up [2] in R_ExpandFileName [3], which
calls R_ExpandFileName_readline [4], which uses libreadline function
tilde_expand [5]. tilde_expand seems to be designed to expand '~'
anywhere in the string it is handed, i.e. operate on whole command
lines, not file paths.

I am taking the liberty of Cc-ing R-devel in case this can be
considered a bug.

-- 
Best regards,
Ivan

[1]
https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807

[2]
https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915

[3]
https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-unix.c#L147

[4]
https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/unix/sys-std.c#L494

[5]
https://git.savannah.gnu.org/cgit/readline.git/tree/tilde.c?h=devel#n187

__
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] Plotting more than one regression line in ggplot

2019-06-06 Thread Rui Barradas

Hello,

You are confusing some of the values of L1 with L1 itself.
If you just want two of those values in your plot, "onepctCO2MEDIAN" and 
"RCP8.5MEDIAN", you need to subset the data filtering out the rows with 
L1 == "RCP4.5MEDIAN".


And please forget geom_jitter, it is completely inappropriate for the 
type of scatter plot you are trying to graph. You jitter when there is 
overplotting, not as a general purpose technique.


Here is one way to do it.


ggplot(subset(NewestdataUltra, L1 != 'RCP4.5MEDIAN'),
   aes(x, value, colour = L1)) +
  geom_point() +
  scale_color_manual(values = c("green", "red")) +
  geom_smooth(method = lm)


Hope this helps,

Rui Barradas

Às 22:37 de 05/06/19, rain1...@aim.com escreveu:

Hi Rui (and everyone),

Thank you so much for your response! Much appreciated!

What if I wanted I create several regression lines and scatter plots in 
the same ggplot using a "melted" dataset? I would like to create a 
scatter plot and regression line for both the objects of 
"onepctCO2MEDIAN" and "RCP8.5MEDIANThis melted dataset looks like this:



 >NewestdataUltra

x variable value L1 1 0.0 y 0. onepctCO2MEDIAN 2 
0.006794447 y 4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607 
onepctCO2MEDIAN 4 0.022087920 y 6.63491326 onepctCO2MEDIAN 5 0.030797357 
y -1.24295056 onepctCO2MEDIAN 6 0.038451072 y 1.56433744 onepctCO2MEDIAN 
7 0.048087904 y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y 2.20700446 
onepctCO2MEDIAN 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10 
0.080524530 y -1.09135062 onepctCO2MEDIAN 11 0.092760246 y 0.40999399 
onepctCO2MEDIAN 12 0.103789609 y -0.12597268 onepctCO2MEDIAN 13 
0.116953168 y -2.41382534 onepctCO2MEDIAN 14 0.129253298 y 7.08902570 
onepctCO2MEDIAN 15 0.141710050 y -0.75935388 onepctCO2MEDIAN 16 
0.156002052 y 0.04544160 onepctCO2MEDIAN 17 0.170648172 y -1.53496826 
onepctCO2MEDIAN 18 0.185318425 y 6.55242014 onepctCO2MEDIAN 19 
0.199463055 y -0.83125628 onepctCO2MEDIAN 20 0.213513337 y -2.50991826 
onepctCO2MEDIAN 21 0.228839271 y 0.13659682 onepctCO2MEDIAN 22 
0.246981293 y -1.37198445 onepctCO2MEDIAN 23 0.263012767 y -0.87129883 
onepctCO2MEDIAN 24 0.278505564 y 0.66325836 onepctCO2MEDIAN 25 
0.293658361 y 0.79380363 onepctCO2MEDIAN 26 0.310747266 y 3.48806374 
onepctCO2MEDIAN 27 0.325990349 y -4.46122081 onepctCO2MEDIAN 28 
0.342517540 y 0.08717340 onepctCO2MEDIAN 29 0.362751633 y -1.41715777 
onepctCO2MEDIAN 30 0.380199537 y -0.99565082 onepctCO2MEDIAN 31 
0.394992948 y 0.32155262 onepctCO2MEDIAN 32 0.414373398 y 3.14038657 
onepctCO2MEDIAN 33 0.430690214 y -0.73760988 onepctCO2MEDIAN 34 
0.449738145 y -2.48605407 onepctCO2MEDIAN 35 0.470167458 y -3.42358584 
onepctCO2MEDIAN 36 0.489019871 y 0.48247475 onepctCO2MEDIAN 37 
0.507242471 y -0.97853863 onepctCO2MEDIAN 38 0.524314284 y 8.53596838 
onepctCO2MEDIAN 39 0.543750525 y 5.48447420 onepctCO2MEDIAN 40 
0.564234197 y 3.21493666 onepctCO2MEDIAN 41 0.583679616 y 3.91689160 
onepctCO2MEDIAN 42 0.601459444 y 4.49070196 onepctCO2MEDIAN 43 
0.619924664 y 6.54104103 onepctCO2MEDIAN 44 0.639932007 y 4.80686500 
onepctCO2MEDIAN 45 0.661347181 y 8.15101701 onepctCO2MEDIAN 46 
0.684117317 y 0.26974132 onepctCO2MEDIAN 47 0.704829752 y -0.18075007 
onepctCO2MEDIAN 48 0.725045770 y 9.71812491 onepctCO2MEDIAN 49 
0.745165825 y 1.54064657 onepctCO2MEDIAN 50 0.765016139 y -1.64760409 
onepctCO2MEDIAN 51 0.783461511 y 4.80246029 onepctCO2MEDIAN 52 
0.806382924 y 4.04215160 onepctCO2MEDIAN 53 0.829241335 y 9.37565122 
onepctCO2MEDIAN 54 0.849924415 y 5.33050497 onepctCO2MEDIAN 55 
0.871352434 y 7.54458026 onepctCO2MEDIAN 56 0.893632233 y 6.46795471 
onepctCO2MEDIAN 57 0.916052133 y 2.80960651 onepctCO2MEDIAN 58 
0.938579470 y 5.39216613 onepctCO2MEDIAN 59 0.959907651 y 7.20436888 
onepctCO2MEDIAN 60 0.981643587 y 3.33508065 onepctCO2MEDIAN 61 
1.004116774 y 8.86907070 onepctCO2MEDIAN 62 1.028363466 y 1.78612989 
onepctCO2MEDIAN 63 1.054009140 y 6.25550382 onepctCO2MEDIAN 64 
1.072440803 y 7.60792365 onepctCO2MEDIAN 65 1.094457805 y 7.68714831 
onepctCO2MEDIAN 66 1.123176277 y 4.77877639 onepctCO2MEDIAN 67 
1.149430871 y 12.71105018 onepctCO2MEDIAN 68 1.170912921 y -0.71562844 
onepctCO2MEDIAN 69 1.196743071 y 1.64908992 onepctCO2MEDIAN 70 
1.218625903 y 3.03630241 onepctCO2MEDIAN 71 1.241868377 y 4.29747688 
onepctCO2MEDIAN 72 1.267941594 y 1.95437781 onepctCO2MEDIAN 73 
1.290708780 y 3.99869637 onepctCO2MEDIAN 74 1.31389 y 4.51794725 
onepctCO2MEDIAN 75 1.339045882 y 0.93379048 onepctCO2MEDIAN 76 
1.362803459 y 3.30507700 onepctCO2MEDIAN 77 1.384450197 y 3.54229702 
onepctCO2MEDIAN 78 1.409720302 y 5.99736597 onepctCO2MEDIAN 79 
1.435851157 y 0.50818686 onepctCO2MEDIAN 80 1.455592215 y 7.96616301 
onepctCO2MEDIAN 81 1.479495347 y 9.94604963 onepctCO2MEDIAN 82 
1.506051958 y 3.79083717 onepctCO2MEDIAN 83 1.525728464 y 2.57358469 
onepctCO2MEDIAN 84 1.549362063 y 10.14049742 onepctCO2MEDIAN 85 
1.573440671 y 13.74083036 onepctCO2MEDIAN 86 1.600278735 y 0.93357712 
onepctCO2MEDIAN 87 1.623879492 y 

Re: [R] debug only top level function

2019-06-06 Thread PIKAL Petr
Thanks Duncan.

I think you found it. I have an object called s within my function. I wanted to 
check it, so I hit "s". This did not bring the object but instead it change 
behaviour of debug function. I did not find this in help pages nor in R exts or 
R intro manual. Maybe it would be worth considering to add something about it 
to debug help page.

Best regards
Petr

> -Original Message-
> From: Duncan Murdoch 
> Sent: Thursday, June 6, 2019 11:11 AM
> To: PIKAL Petr ; r-help@r-project.org
> Subject: Re: [R] debug only top level function
>
> On 06/06/2019 4:55 a.m., PIKAL Petr wrote:
> > Dear all
> >
> > I have a question about debug function. I did not use it for long time but 
> > my
> vague memory tell me, that when I used  debug(myfunction) in past, only
> myfunction was debugged and browser ignored any embedded function.
> >
> > example (simple)
> >
> > fff <- function(x) mean(x, na.rm=T)
> >
> > when I issue
> >> debug(fff)
> >> fff(1:10)
> > debugging in: fff(1:10)
> > debug at #1: mean(x, na.rm = T)
> > Browse[2]>
> > debugging in: mean(x, na.rm = T)
> > debug: UseMethod("mean")
> > Browse[3]>
> > debugging in: mean.default(x, na.rm = T) ...
> > it starts debugging mean function. I understand that it is indicated by
> Browse[n] but it could be quite messy if I have many embedded functions and
> difficult to follow.
> >
> > Can I persuade debug function not to bother with embedded functions (e.g.
> mean, median, mad, ...) and debug only my top level code?
>
> There are several commands available.  Type "help" to see them:
>
> n  next
> s  step into
> f  finish
> c or cont  continue
> Q  quit
> where  show stack
> help   show help
>  evaluate expression
>
>
> You want "n", and are getting "s".  I believe if you hit Enter without 
> choosing
> one, it will do the same as the previous time, so you've probably used "s"
> sometime in the past.
>
> Duncan Murdoch
>
> >
> > Best regards
> > Petr
> >
> >> sessionInfo()
> > R Under development (unstable) (2018-03-07 r74369)
> > Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10
> > x64 (build 17763)
> >
> > Matrix products: default
> >
> > locale:
> > [1] LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250 [3]
> > LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C [5]
> > LC_TIME=Czech_Czechia.1250
> >
> > attached base packages:
> > [1] stats datasets  utils grDevices graphics  methods   base
> >
> > other attached packages:
> > [1] MASS_7.3-49 readxl_1.0.0lattice_0.20-35 fun_0.1
> >
> > loaded via a namespace (and not attached):
> > [1] Rcpp_0.12.16 cellranger_1.1.0 grid_3.5.0   plyr_1.8.4
> >   [5] gtable_0.2.0 scales_0.5.0 ggplot2_2.2.1pillar_1.2.1
> >   [9] rlang_0.2.0  lazyeval_0.2.1   rpart_4.1-13 tools_3.5.0
> > [13] munsell_0.4.3compiler_3.5.0   colorspace_1.3-2 tibble_1.4.2
> >>
> > __
> > 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.
> >

Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner’s personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/

__
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] debug only top level function

2019-06-06 Thread Duncan Murdoch

On 06/06/2019 4:55 a.m., PIKAL Petr wrote:

Dear all

I have a question about debug function. I did not use it for long time but my 
vague memory tell me, that when I used  debug(myfunction) in past, only 
myfunction was debugged and browser ignored any embedded function.

example (simple)

fff <- function(x) mean(x, na.rm=T)

when I issue

debug(fff)
fff(1:10)

debugging in: fff(1:10)
debug at #1: mean(x, na.rm = T)
Browse[2]>
debugging in: mean(x, na.rm = T)
debug: UseMethod("mean")
Browse[3]>
debugging in: mean.default(x, na.rm = T)
...
it starts debugging mean function. I understand that it is indicated by 
Browse[n] but it could be quite messy if I have many embedded functions and 
difficult to follow.

Can I persuade debug function not to bother with embedded functions (e.g. mean, 
median, mad, ...) and debug only my top level code?


There are several commands available.  Type "help" to see them:

n  next
s  step into
f  finish
c or cont  continue
Q  quit
where  show stack
help   show help
 evaluate expression


You want "n", and are getting "s".  I believe if you hit Enter without 
choosing one, it will do the same as the previous time, so you've 
probably used "s" sometime in the past.


Duncan Murdoch



Best regards
Petr


sessionInfo()

R Under development (unstable) (2018-03-07 r74369)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250
[3] LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C
[5] LC_TIME=Czech_Czechia.1250

attached base packages:
[1] stats datasets  utils grDevices graphics  methods   base

other attached packages:
[1] MASS_7.3-49 readxl_1.0.0lattice_0.20-35 fun_0.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 cellranger_1.1.0 grid_3.5.0   plyr_1.8.4
  [5] gtable_0.2.0 scales_0.5.0 ggplot2_2.2.1pillar_1.2.1
  [9] rlang_0.2.0  lazyeval_0.2.1   rpart_4.1-13 tools_3.5.0
[13] munsell_0.4.3compiler_3.5.0   colorspace_1.3-2 tibble_1.4.2



Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch 
partner? PRECHEZA a.s. jsou zve?ejn?ny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner's personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a 
podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/


[[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-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] debug only top level function

2019-06-06 Thread PIKAL Petr
Dear all

I have a question about debug function. I did not use it for long time but my 
vague memory tell me, that when I used  debug(myfunction) in past, only 
myfunction was debugged and browser ignored any embedded function.

example (simple)

fff <- function(x) mean(x, na.rm=T)

when I issue
> debug(fff)
> fff(1:10)
debugging in: fff(1:10)
debug at #1: mean(x, na.rm = T)
Browse[2]>
debugging in: mean(x, na.rm = T)
debug: UseMethod("mean")
Browse[3]>
debugging in: mean.default(x, na.rm = T)
...
it starts debugging mean function. I understand that it is indicated by 
Browse[n] but it could be quite messy if I have many embedded functions and 
difficult to follow.

Can I persuade debug function not to bother with embedded functions (e.g. mean, 
median, mad, ...) and debug only my top level code?

Best regards
Petr

> sessionInfo()
R Under development (unstable) (2018-03-07 r74369)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=Czech_Czechia.1250  LC_CTYPE=Czech_Czechia.1250
[3] LC_MONETARY=Czech_Czechia.1250 LC_NUMERIC=C
[5] LC_TIME=Czech_Czechia.1250

attached base packages:
[1] stats datasets  utils grDevices graphics  methods   base

other attached packages:
[1] MASS_7.3-49 readxl_1.0.0lattice_0.20-35 fun_0.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 cellranger_1.1.0 grid_3.5.0   plyr_1.8.4
 [5] gtable_0.2.0 scales_0.5.0 ggplot2_2.2.1pillar_1.2.1
 [9] rlang_0.2.0  lazyeval_0.2.1   rpart_4.1-13 tools_3.5.0
[13] munsell_0.4.3compiler_3.5.0   colorspace_1.3-2 tibble_1.4.2
>
Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch 
partner? PRECHEZA a.s. jsou zve?ejn?ny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner's personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a 
podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/


[[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] Plotting more than one regression line in ggplot

2019-06-06 Thread PIKAL Petr
Hi

It is probably time to consult documentation, including R-Intro. GGplot 
paradigm is that you have set of values (x,y) and factor variable(s) used for 
changing colour, size, plotting character or several other plot items.

so something like
pl <- ggplot(NewestdataULTRA, aes(x=x, y=value, colour=L1))
pl +geom_point()+geom_smooth(method="lm")

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of rain1290--- via R-
> help
> Sent: Wednesday, June 5, 2019 11:37 PM
> To: ruipbarra...@sapo.pt; r-help@R-project.org; r-sig-...@r-project.org
> Subject: Re: [R] Plotting more than one regression line in ggplot
>
> Hi Rui (and everyone),
>
> Thank you so much for your response! Much appreciated!
> What if I wanted I create several regression lines and scatter plots in the 
> same
> ggplot using a "melted" dataset? I would like to create a scatter plot and
> regression line for both the objects of "onepctCO2MEDIAN" and
> "RCP8.5MEDIANThis melted dataset looks like this:
>
> >NewestdataUltra
>  x variable   value  L1
> 1   0.0y  0. onepctCO2MEDIAN
> 2   0.006794447y  4.90024902 onepctCO2MEDIAN
> 3   0.014288058y  0.1607 onepctCO2MEDIAN
> 4   0.022087920y  6.63491326 onepctCO2MEDIAN
> 5   0.030797357y -1.24295056 onepctCO2MEDIAN
> 6   0.038451072y  1.56433744 onepctCO2MEDIAN
> 7   0.048087904y -2.26590352 onepctCO2MEDIAN
> 8   0.058677729y  2.20700446 onepctCO2MEDIAN
> 9   0.069261406y -2.36770013 onepctCO2MEDIAN
> 10  0.080524530y -1.09135062 onepctCO2MEDIAN
> 11  0.092760246y  0.40999399 onepctCO2MEDIAN
> 12  0.103789609y -0.12597268 onepctCO2MEDIAN
> 13  0.116953168y -2.41382534 onepctCO2MEDIAN
> 14  0.129253298y  7.08902570 onepctCO2MEDIAN
> 15  0.141710050y -0.75935388 onepctCO2MEDIAN
> 16  0.156002052y  0.04544160 onepctCO2MEDIAN
> 17  0.170648172y -1.53496826 onepctCO2MEDIAN
> 18  0.185318425y  6.55242014 onepctCO2MEDIAN
> 19  0.199463055y -0.83125628 onepctCO2MEDIAN
> 20  0.213513337y -2.50991826 onepctCO2MEDIAN
> 21  0.228839271y  0.13659682 onepctCO2MEDIAN
> 22  0.246981293y -1.37198445 onepctCO2MEDIAN
> 23  0.263012767y -0.87129883 onepctCO2MEDIAN
> 24  0.278505564y  0.66325836 onepctCO2MEDIAN
> 25  0.293658361y  0.79380363 onepctCO2MEDIAN
> 26  0.310747266y  3.48806374 onepctCO2MEDIAN
> 27  0.325990349y -4.46122081 onepctCO2MEDIAN
> 28  0.342517540y  0.08717340 onepctCO2MEDIAN
> 29  0.362751633y -1.41715777 onepctCO2MEDIAN
> 30  0.380199537y -0.99565082 onepctCO2MEDIAN
> 31  0.394992948y  0.32155262 onepctCO2MEDIAN
> 32  0.414373398y  3.14038657 onepctCO2MEDIAN
> 33  0.430690214y -0.73760988 onepctCO2MEDIAN
> 34  0.449738145y -2.48605407 onepctCO2MEDIAN
> 35  0.470167458y -3.42358584 onepctCO2MEDIAN
> 36  0.489019871y  0.48247475 onepctCO2MEDIAN
> 37  0.507242471y -0.97853863 onepctCO2MEDIAN
> 38  0.524314284y  8.53596838 onepctCO2MEDIAN
> 39  0.543750525y  5.48447420 onepctCO2MEDIAN
> 40  0.564234197y  3.21493666 onepctCO2MEDIAN
> 41  0.583679616y  3.91689160 onepctCO2MEDIAN
> 42  0.601459444y  4.49070196 onepctCO2MEDIAN
> 43  0.619924664y  6.54104103 onepctCO2MEDIAN
> 44  0.639932007y  4.80686500 onepctCO2MEDIAN
> 45  0.661347181y  8.15101701 onepctCO2MEDIAN
> 46  0.684117317y  0.26974132 onepctCO2MEDIAN
> 47  0.704829752y -0.18075007 onepctCO2MEDIAN
> 48  0.725045770y  9.71812491 onepctCO2MEDIAN
> 49  0.745165825y  1.54064657 onepctCO2MEDIAN
> 50  0.765016139y -1.64760409 onepctCO2MEDIAN
> 51  0.783461511y  4.80246029 onepctCO2MEDIAN
> 52  0.806382924y  4.04215160 onepctCO2MEDIAN
> 53  0.829241335y  9.37565122 onepctCO2MEDIAN
> 54  0.849924415y  5.33050497 onepctCO2MEDIAN
> 55  0.871352434y  7.54458026 onepctCO2MEDIAN
> 56  0.893632233y  6.46795471 onepctCO2MEDIAN
> 57  0.916052133y  2.80960651 onepctCO2MEDIAN
> 58  0.938579470y  5.39216613 onepctCO2MEDIAN
> 59  0.959907651y  7.20436888 onepctCO2MEDIAN
> 60  0.981643587y  3.33508065 onepctCO2MEDIAN
> 61  1.004116774y  8.86907070 onepctCO2MEDIAN
> 62  1.028363466y  1.78612989 onepctCO2MEDIAN
> 63  1.054009140y  6.25550382 onepctCO2MEDIAN
> 64  1.072440803y  7.60792365 onepctCO2MEDIAN
> 65  1.094457805y  7.68714831 onepctCO2MEDIAN
> 66  1.123176277y  4.77877639 onepctCO2MEDIAN
> 67  1.149430871y 12.71105018 onepctCO2MEDIAN
> 68  1.170912921y -0.71562844 onepctCO2MEDIAN
> 69  1.196743071y  1.64908992 onepctCO2MEDIAN
> 70  1.218625903y  3.03630241 onepctCO2MEDIAN
> 71  1.241868377y  4.29747688 onepctCO2MEDIAN
> 72  1.267941594y  

Re: [R] Open a file which name contains a tilde

2019-06-06 Thread Enrico Schumann



Quoting Frank Schwidom :


On 2019-06-05 20:32:07, Enrico Schumann wrote:

> "FS" == Frank Schwidom  writes:

FS> Hi,
FS> As I can see via path.expand a filename which contains a 
 FS> tilde anywhere gets automatically crippled.


FS> +> path.expand("a ~ b")
FS> [1] "a /home/user b"

FS> +> path.expand("a ~ b ~")
FS> [1] "a /home/user b /home/user"

FS> I want to open a file regardless whether its name contains   
   FS> any character unless 0.


FS> The unix filesystem allow the creation of such files, it 
 FS> sould be possible to open these.


FS> How can I switch off any file crippling activity?

FS> Kind regards,
FS> Frank

Do you need 'path.expand'? For example,

readLines("~/Desktop/a ~ b")

reads just fine the content of a file named
'a ~ b' on my desktop.



Appendix:

I found out in the meantime that I can use 'R --no-readline' but I  
want to use readline and I found no possible readline configuration  
/etc/inputrc).


And maybe it works as Rscript.

But that should be more consistent because it is in fact very basic.

Kind regards,
Frank


You're right. I ran the example from Emacs/ESS.
There it worked, but only because ESS uses '--no-readline'
as a default (i.e. 'ess-R-readline' is set to nil).
With readline enabled, it fails (with R 3.6.0).


--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

__
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.