Re: [R] How to spot/stop making the same mistake

2021-06-23 Thread Avi Gross via R-help
Just a caution. There IS an operator of `!!` in the tidyverse called "bang 
bang" that does a kind of substitution and you can look up the help page for it 
as:

?`!!`

I just tried it on an example and it definitely will in some cases do this 
other evaluation.

I doubt this will clash, but of course parentheses can force the normal 
evaluation as in !(!(a))

And there is a !!! symbol there too to make a big bang, theoretically.

But not for novices 

-Original Message-
From: R-help  On Behalf Of Jeff Newmiller
Sent: Wednesday, June 23, 2021 2:10 PM
To: r-help@r-project.org; Phillips Rogfield ; Bert 
Gunter ; Eric Berger 
Cc: r-help@r-project.org
Subject: Re: [R] How to spot/stop making the same mistake

For the record, `!!` is not an operator so it does not "operate" on anything. 
The right ! does per the help page (?`!`) interpret non-zero values as TRUE and 
invert that logic, yielding a logical result even if the input is not logical. 
The left ! inverts that again, yielding a logical vector without the inversion.

On June 23, 2021 10:39:07 AM PDT, Phillips Rogfield  
wrote:
>Dear all,
>
>thank for for your suggestion.
>
>Yes I come from languages where 1 means TRUE and 0 means FALSE. In 
>particular from C/C++ and Python.
>
>Evidently this is not the case for R.
>
>In my mind I kind took for granted that that was the case (1=TRUE, 
>0=FALSE).
>
>Knowing this is not the case for R makes things simpler.
>
>Mine was just an example, sometimes I load datasets taken from outside 
>and variables are coded with 1/0 (for example, a treatment variable may
>
>be coded that way).
>
>I also did not know the !!() syntax!
>
>Thank you for your help and best regards.
>
>On 23/06/2021 17:55, Bert Gunter wrote:
>> Just as a way to save a bit of typing, instead of
>>
>> > as.logical(0:4)
>> [1] FALSE  TRUE  TRUE  TRUE  TRUE
>>
>> > !!(0:4)
>> [1] FALSE  TRUE  TRUE  TRUE  TRUE
>>
>> DO NOTE that the parentheses in the second expression should never be
>
>> omitted, a possible reason to prefer the as.logical() construction.
>> Also note that !!  "acts [only] on raw, logical and number-like 
>> vectors," whereas as.logical() is more general. e.g. (from ?logical):
>>
>> > charvec <- c("FALSE", "F", "False", "false","fAlse", "0",
>> +  "TRUE",  "T", "True",  "true", "tRue",  "1")
>> > as.logical(charvec)
>>  [1] FALSE FALSE FALSE FALSENANA  TRUE  TRUE  TRUE  TRUE
> NA
>>NA
>> > !!charvec
>> Error in !charvec : invalid argument type
>>
>>
>> Cheers,
>> Bert
>>
>> 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 Wed, Jun 23, 2021 at 8:31 AM Eric Berger > > wrote:
>>
>> In my code, instead of 't', I name a vector of indices with a
>> meaningful
>> name, such as idxV, to make it obvious.
>>
>> Alternatively, a minor change in your style would be to replace
>your
>> definition of t by
>>
>> t <- as.logical(c(1,1,1,0,0))
>>
>> HTH,
>> Eric
>>
>>
>> On Wed, Jun 23, 2021 at 6:11 PM Phillips Rogfield
>> mailto:thebudge...@gmail.com>>
>> wrote:
>>
>> > I make the same mistake all over again.
>> >
>> > In particular, suppose we have:
>> >
>> > a = c(1,2,3,4,5)
>> >
>> > and a variable that equals 1 for the elements I want to select:
>> >
>> > t = c(1,1,1,0,0)
>> >
>> > To select the first 3 elements.
>> >
>> > The problem is that
>> >
>> > a[t]
>> >
>> > would repeat the first element 3 times .
>> >
>> > I have to either convert `t` to boolean:
>> >
>> > a[t==1]
>> >
>> > Or use `which`
>> >
>> > a[which(t==1)]
>> >
>> > How can I "spot" this error?
>> >
>> > It often happens in long scripts.
>> >
>> > Do I have to check the type each time?
>> >
>> > Do you have any suggestions?
>> >
>> > __
>> > 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
>> 

Re: [R] Special characters in cell names

2021-06-23 Thread David Winsemius
On my keyboard the key is share with the tilde symbol and is up on the left 
hand corner. 

Sent from my iPhone

> On Jun 23, 2021, at 2:45 PM, David Winsemius  wrote:
> 
> Backticks. NOT apostrophes. 
> 
> — David
> 
> Sent from my iPhone
> 
>> On Jun 23, 2021, at 2:40 PM, Mahmood Naderan  wrote:
>> 
>> Hi Bert,
>> I don't know what does "check.names" do here, but my commands look like
>> 
>> 
>>> mydata <- read.csv('r.3080..csv', header=T,row.names=1)
>> 
>>> head(mydata)
>> W  AX/Y
>> P1   M  1.469734 0.004144405
>> P2M 20.584841 0.008010306
>> P3 M 53.519800 0.166034888
>> P4  M 42.308700 0.051545443
>> P5   M 99.236384 0.893037857
>> P6M 94.279504 0.856837525
>> 
>> So when I use
>> 
>> p <- ggplot(mydata, aes(x=W, y='X/Y')) + geom_violin(trim=FALSE)
>> 
>> 
>> The output is not correct. I don't see values (scale) on the y-axis.
>> Anyway, I fixed that with a label.
>> 
>> Regards,
>> Mahmood
>> 
>> 
>> 
>> 
 On Wed, Jun 23, 2021 at 11:16 PM Bert Gunter  
 wrote:
>>> 
>>> I found your specification quite vague. What did you mean by a "data file"
>>> -- a data frame in R? -- a file in the file system?
>>> 
>>> I may be completely wrong here, but another possibility is that you read
>>> your data into an R data.frame via, e.g. read.table() or read.csv(), but
>>> failed to specify the check.names = FALSE, argument. This would cause a
>>> column named "x/y" in your original table to be given the name "x.y" in R,
>>> as "x/y" is not a syntactically valid name. See ?make.names for details.
>>> 
>>> As others have already said, enclosing non-syntactically valid names in
>>> back ticks usually works (maybe always works??). So for example:
>>> 
>>> z<-data.frame (`a/b` = 1:5, y = 1:5, check.names = FALSE)
>>> plot(y ~ `a/b`, data = z) ## produces desired plot with correct label
>>> z  ## yields:
>>> a/b y
>>> 1   1 1
>>> 2   2 2
>>> 3   3 3
>>> 4   4 4
>>> 5   5 5
>>> 
>>> Of course, ignore if this is all irrelevant.
>>> 
>>> 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 Wed, Jun 23, 2021 at 1:37 PM Mahmood Naderan 
>>> wrote:
>>> 
 Unfortunately, using 'X/Y' doesn't work either.
 Instead I used labels like below
 
 P + scale_y_continuous(name="X/Y")
 
 Thanks for the suggestions.
 
 Regards,
 Mahmood
 
 
 
 
 On Wed, Jun 23, 2021 at 9:22 PM Eric Berger 
 wrote:
 
> If no one comes up with a better suggestion:
> a. Change the column name to "Y" so that you get the plot you want
> b. Use axis labels and legend text to show the text that you want. (The
> user never has to know that you changed the column name )
> 
> HTH,
> Eric
> 
> On Wed, Jun 23, 2021 at 9:58 PM Mahmood Naderan 
> wrote:
> 
>> Hi
>> I have a column in my data file which is "X/Y". With '/' I want to
>> emphasize that values are the ratio of X over Y.
>> Problem is that in the following command for a violin plot, I am not
 able
>> to specify that '/' even with double quotes.
>> 
>> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
>> 
>> However, if I change that column to "Y" and use
>> 
>> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
>> 
>> Then the plot will be correctly shown.
>> Any ideas for that?
>> 
>> Regards,
>> Mahmood
>> 
>>   [[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.
 
>>> 
>> 
>>   [[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 

Re: [R] Special characters in cell names

2021-06-23 Thread Mahmood Naderan
OK I understand. Thanks a lot.


Regards,
Mahmood




On Wed, Jun 23, 2021 at 11:46 PM Bert Gunter  wrote:

> Try:
> ggplot(mydata, aes(x=W, y=`X/Y`)) + geom_violin(trim=FALSE)
>
> Note the use of *backticks*, ``, not single quotes, ' '  . ** They are
> different.**
>
> So, yes, your data got read in correctly, presumably because "/" is
> considered a character in your locale. It is not in mine. So my suggestion
> was indeed irrelevant.
>
> 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 Wed, Jun 23, 2021 at 2:39 PM Mahmood Naderan 
> wrote:
>
>> Hi Bert,
>> I don't know what does "check.names" do here, but my commands look like
>>
>>
>> > mydata <- read.csv('r.3080..csv', header=T,row.names=1)
>>
>> > head(mydata)
>>   W  AX/Y
>> P1   M  1.469734 0.004144405
>> P2M 20.584841 0.008010306
>> P3 M 53.519800 0.166034888
>> P4  M 42.308700 0.051545443
>> P5   M 99.236384 0.893037857
>> P6M 94.279504 0.856837525
>>
>> So when I use
>>
>> p <- ggplot(mydata, aes(x=W, y='X/Y')) + geom_violin(trim=FALSE)
>>
>>
>> The output is not correct. I don't see values (scale) on the y-axis.
>> Anyway, I fixed that with a label.
>>
>> Regards,
>> Mahmood
>>
>>
>>
>>
>> On Wed, Jun 23, 2021 at 11:16 PM Bert Gunter 
>> wrote:
>>
>>> I found your specification quite vague. What did you mean by a "data
>>> file" -- a data frame in R? -- a file in the file system?
>>>
>>> I may be completely wrong here, but another possibility is that you read
>>> your data into an R data.frame via, e.g. read.table() or read.csv(), but
>>> failed to specify the check.names = FALSE, argument. This would cause a
>>> column named "x/y" in your original table to be given the name "x.y" in R,
>>> as "x/y" is not a syntactically valid name. See ?make.names for details.
>>>
>>> As others have already said, enclosing non-syntactically valid names in
>>> back ticks usually works (maybe always works??). So for example:
>>>
>>> z<-data.frame (`a/b` = 1:5, y = 1:5, check.names = FALSE)
>>> plot(y ~ `a/b`, data = z) ## produces desired plot with correct label
>>> z  ## yields:
>>>   a/b y
>>> 1   1 1
>>> 2   2 2
>>> 3   3 3
>>> 4   4 4
>>> 5   5 5
>>>
>>> Of course, ignore if this is all irrelevant.
>>>
>>> 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 Wed, Jun 23, 2021 at 1:37 PM Mahmood Naderan 
>>> wrote:
>>>
 Unfortunately, using 'X/Y' doesn't work either.
 Instead I used labels like below

 P + scale_y_continuous(name="X/Y")

 Thanks for the suggestions.

 Regards,
 Mahmood




 On Wed, Jun 23, 2021 at 9:22 PM Eric Berger 
 wrote:

 > If no one comes up with a better suggestion:
 > a. Change the column name to "Y" so that you get the plot you want
 > b. Use axis labels and legend text to show the text that you want.
 (The
 > user never has to know that you changed the column name )
 >
 > HTH,
 > Eric
 >
 > On Wed, Jun 23, 2021 at 9:58 PM Mahmood Naderan >>> >
 > wrote:
 >
 >> Hi
 >> I have a column in my data file which is "X/Y". With '/' I want to
 >> emphasize that values are the ratio of X over Y.
 >> Problem is that in the following command for a violin plot, I am not
 able
 >> to specify that '/' even with double quotes.
 >>
 >> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
 >>
 >> However, if I change that column to "Y" and use
 >>
 >> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
 >>
 >> Then the plot will be correctly shown.
 >> Any ideas for that?
 >>
 >> Regards,
 >> Mahmood
 >>
 >> [[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.

>>>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To 

Re: [R] Special characters in cell names

2021-06-23 Thread Bert Gunter
Try:
ggplot(mydata, aes(x=W, y=`X/Y`)) + geom_violin(trim=FALSE)

Note the use of *backticks*, ``, not single quotes, ' '  . ** They are
different.**

So, yes, your data got read in correctly, presumably because "/" is
considered a character in your locale. It is not in mine. So my suggestion
was indeed irrelevant.

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 Wed, Jun 23, 2021 at 2:39 PM Mahmood Naderan 
wrote:

> Hi Bert,
> I don't know what does "check.names" do here, but my commands look like
>
>
> > mydata <- read.csv('r.3080..csv', header=T,row.names=1)
>
> > head(mydata)
>   W  AX/Y
> P1   M  1.469734 0.004144405
> P2M 20.584841 0.008010306
> P3 M 53.519800 0.166034888
> P4  M 42.308700 0.051545443
> P5   M 99.236384 0.893037857
> P6M 94.279504 0.856837525
>
> So when I use
>
> p <- ggplot(mydata, aes(x=W, y='X/Y')) + geom_violin(trim=FALSE)
>
>
> The output is not correct. I don't see values (scale) on the y-axis.
> Anyway, I fixed that with a label.
>
> Regards,
> Mahmood
>
>
>
>
> On Wed, Jun 23, 2021 at 11:16 PM Bert Gunter 
> wrote:
>
>> I found your specification quite vague. What did you mean by a "data
>> file" -- a data frame in R? -- a file in the file system?
>>
>> I may be completely wrong here, but another possibility is that you read
>> your data into an R data.frame via, e.g. read.table() or read.csv(), but
>> failed to specify the check.names = FALSE, argument. This would cause a
>> column named "x/y" in your original table to be given the name "x.y" in R,
>> as "x/y" is not a syntactically valid name. See ?make.names for details.
>>
>> As others have already said, enclosing non-syntactically valid names in
>> back ticks usually works (maybe always works??). So for example:
>>
>> z<-data.frame (`a/b` = 1:5, y = 1:5, check.names = FALSE)
>> plot(y ~ `a/b`, data = z) ## produces desired plot with correct label
>> z  ## yields:
>>   a/b y
>> 1   1 1
>> 2   2 2
>> 3   3 3
>> 4   4 4
>> 5   5 5
>>
>> Of course, ignore if this is all irrelevant.
>>
>> 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 Wed, Jun 23, 2021 at 1:37 PM Mahmood Naderan 
>> wrote:
>>
>>> Unfortunately, using 'X/Y' doesn't work either.
>>> Instead I used labels like below
>>>
>>> P + scale_y_continuous(name="X/Y")
>>>
>>> Thanks for the suggestions.
>>>
>>> Regards,
>>> Mahmood
>>>
>>>
>>>
>>>
>>> On Wed, Jun 23, 2021 at 9:22 PM Eric Berger 
>>> wrote:
>>>
>>> > If no one comes up with a better suggestion:
>>> > a. Change the column name to "Y" so that you get the plot you want
>>> > b. Use axis labels and legend text to show the text that you want. (The
>>> > user never has to know that you changed the column name )
>>> >
>>> > HTH,
>>> > Eric
>>> >
>>> > On Wed, Jun 23, 2021 at 9:58 PM Mahmood Naderan 
>>> > wrote:
>>> >
>>> >> Hi
>>> >> I have a column in my data file which is "X/Y". With '/' I want to
>>> >> emphasize that values are the ratio of X over Y.
>>> >> Problem is that in the following command for a violin plot, I am not
>>> able
>>> >> to specify that '/' even with double quotes.
>>> >>
>>> >> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
>>> >>
>>> >> However, if I change that column to "Y" and use
>>> >>
>>> >> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
>>> >>
>>> >> Then the plot will be correctly shown.
>>> >> Any ideas for that?
>>> >>
>>> >> Regards,
>>> >> Mahmood
>>> >>
>>> >> [[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.
>>>
>>

[[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] Special characters in cell names

2021-06-23 Thread David Winsemius
Backticks. NOT apostrophes. 

— David

Sent from my iPhone

> On Jun 23, 2021, at 2:40 PM, Mahmood Naderan  wrote:
> 
> Hi Bert,
> I don't know what does "check.names" do here, but my commands look like
> 
> 
>> mydata <- read.csv('r.3080..csv', header=T,row.names=1)
> 
>> head(mydata)
>  W  AX/Y
> P1   M  1.469734 0.004144405
> P2M 20.584841 0.008010306
> P3 M 53.519800 0.166034888
> P4  M 42.308700 0.051545443
> P5   M 99.236384 0.893037857
> P6M 94.279504 0.856837525
> 
> So when I use
> 
> p <- ggplot(mydata, aes(x=W, y='X/Y')) + geom_violin(trim=FALSE)
> 
> 
> The output is not correct. I don't see values (scale) on the y-axis.
> Anyway, I fixed that with a label.
> 
> Regards,
> Mahmood
> 
> 
> 
> 
>> On Wed, Jun 23, 2021 at 11:16 PM Bert Gunter  wrote:
>> 
>> I found your specification quite vague. What did you mean by a "data file"
>> -- a data frame in R? -- a file in the file system?
>> 
>> I may be completely wrong here, but another possibility is that you read
>> your data into an R data.frame via, e.g. read.table() or read.csv(), but
>> failed to specify the check.names = FALSE, argument. This would cause a
>> column named "x/y" in your original table to be given the name "x.y" in R,
>> as "x/y" is not a syntactically valid name. See ?make.names for details.
>> 
>> As others have already said, enclosing non-syntactically valid names in
>> back ticks usually works (maybe always works??). So for example:
>> 
>> z<-data.frame (`a/b` = 1:5, y = 1:5, check.names = FALSE)
>> plot(y ~ `a/b`, data = z) ## produces desired plot with correct label
>> z  ## yields:
>>  a/b y
>> 1   1 1
>> 2   2 2
>> 3   3 3
>> 4   4 4
>> 5   5 5
>> 
>> Of course, ignore if this is all irrelevant.
>> 
>> 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 Wed, Jun 23, 2021 at 1:37 PM Mahmood Naderan 
>> wrote:
>> 
>>> Unfortunately, using 'X/Y' doesn't work either.
>>> Instead I used labels like below
>>> 
>>> P + scale_y_continuous(name="X/Y")
>>> 
>>> Thanks for the suggestions.
>>> 
>>> Regards,
>>> Mahmood
>>> 
>>> 
>>> 
>>> 
>>> On Wed, Jun 23, 2021 at 9:22 PM Eric Berger 
>>> wrote:
>>> 
 If no one comes up with a better suggestion:
 a. Change the column name to "Y" so that you get the plot you want
 b. Use axis labels and legend text to show the text that you want. (The
 user never has to know that you changed the column name )
 
 HTH,
 Eric
 
 On Wed, Jun 23, 2021 at 9:58 PM Mahmood Naderan 
 wrote:
 
> Hi
> I have a column in my data file which is "X/Y". With '/' I want to
> emphasize that values are the ratio of X over Y.
> Problem is that in the following command for a violin plot, I am not
>>> able
> to specify that '/' even with double quotes.
> 
> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
> 
> However, if I change that column to "Y" and use
> 
> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
> 
> Then the plot will be correctly shown.
> Any ideas for that?
> 
> Regards,
> Mahmood
> 
>[[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.
>>> 
>> 
> 
>[[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] Special characters in cell names

2021-06-23 Thread Mahmood Naderan
Hi Bert,
I don't know what does "check.names" do here, but my commands look like


> mydata <- read.csv('r.3080..csv', header=T,row.names=1)

> head(mydata)
  W  AX/Y
P1   M  1.469734 0.004144405
P2M 20.584841 0.008010306
P3 M 53.519800 0.166034888
P4  M 42.308700 0.051545443
P5   M 99.236384 0.893037857
P6M 94.279504 0.856837525

So when I use

p <- ggplot(mydata, aes(x=W, y='X/Y')) + geom_violin(trim=FALSE)


The output is not correct. I don't see values (scale) on the y-axis.
Anyway, I fixed that with a label.

Regards,
Mahmood




On Wed, Jun 23, 2021 at 11:16 PM Bert Gunter  wrote:

> I found your specification quite vague. What did you mean by a "data file"
> -- a data frame in R? -- a file in the file system?
>
> I may be completely wrong here, but another possibility is that you read
> your data into an R data.frame via, e.g. read.table() or read.csv(), but
> failed to specify the check.names = FALSE, argument. This would cause a
> column named "x/y" in your original table to be given the name "x.y" in R,
> as "x/y" is not a syntactically valid name. See ?make.names for details.
>
> As others have already said, enclosing non-syntactically valid names in
> back ticks usually works (maybe always works??). So for example:
>
> z<-data.frame (`a/b` = 1:5, y = 1:5, check.names = FALSE)
> plot(y ~ `a/b`, data = z) ## produces desired plot with correct label
> z  ## yields:
>   a/b y
> 1   1 1
> 2   2 2
> 3   3 3
> 4   4 4
> 5   5 5
>
> Of course, ignore if this is all irrelevant.
>
> 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 Wed, Jun 23, 2021 at 1:37 PM Mahmood Naderan 
> wrote:
>
>> Unfortunately, using 'X/Y' doesn't work either.
>> Instead I used labels like below
>>
>> P + scale_y_continuous(name="X/Y")
>>
>> Thanks for the suggestions.
>>
>> Regards,
>> Mahmood
>>
>>
>>
>>
>> On Wed, Jun 23, 2021 at 9:22 PM Eric Berger 
>> wrote:
>>
>> > If no one comes up with a better suggestion:
>> > a. Change the column name to "Y" so that you get the plot you want
>> > b. Use axis labels and legend text to show the text that you want. (The
>> > user never has to know that you changed the column name )
>> >
>> > HTH,
>> > Eric
>> >
>> > On Wed, Jun 23, 2021 at 9:58 PM Mahmood Naderan 
>> > wrote:
>> >
>> >> Hi
>> >> I have a column in my data file which is "X/Y". With '/' I want to
>> >> emphasize that values are the ratio of X over Y.
>> >> Problem is that in the following command for a violin plot, I am not
>> able
>> >> to specify that '/' even with double quotes.
>> >>
>> >> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
>> >>
>> >> However, if I change that column to "Y" and use
>> >>
>> >> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
>> >>
>> >> Then the plot will be correctly shown.
>> >> Any ideas for that?
>> >>
>> >> Regards,
>> >> Mahmood
>> >>
>> >> [[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.
>>
>

[[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] How to spot/stop making the same mistake

2021-06-23 Thread William Michels via R-help
Hi Phillips,

Maybe these examples will be useful:

> vec <- c("a","b","c","d","e")
> vec[c(1,1,1,0,0)]
[1] "a" "a" "a"
> vec[c(1,1,1,2,2)]
[1] "a" "a" "a" "b" "b"
> vec[c(5,5,5,5,5)]
[1] "e" "e" "e" "e" "e"
> vec[c(NA,NA,NA,0,0,0,0)]
[1] NA NA NA
> vec[c(NA,NA,NA,1,1,1,1)]
[1] NA  NA  NA  "a" "a" "a" "a"
> vec[c(7:9)]
[1] NA NA NA
>
> R.version.string
[1] "R version 3.6.3 (2020-02-29)"

HTH, Bill.

W. Michels, Ph.D.








On Wed, Jun 23, 2021 at 10:39 AM Phillips Rogfield
 wrote:
>
> Dear all,
>
> thank for for your suggestion.
>
> Yes I come from languages where 1 means TRUE and 0 means FALSE. In
> particular from C/C++ and Python.
>
> Evidently this is not the case for R.
>
> In my mind I kind took for granted that that was the case (1=TRUE, 0=FALSE).
>
> Knowing this is not the case for R makes things simpler.
>
> Mine was just an example, sometimes I load datasets taken from outside
> and variables are coded with 1/0 (for example, a treatment variable may
> be coded that way).
>
> I also did not know the !!() syntax!
>
> Thank you for your help and best regards.
>
> On 23/06/2021 17:55, Bert Gunter wrote:
> > Just as a way to save a bit of typing, instead of
> >
> > > as.logical(0:4)
> > [1] FALSE  TRUE  TRUE  TRUE  TRUE
> >
> > > !!(0:4)
> > [1] FALSE  TRUE  TRUE  TRUE  TRUE
> >
> > DO NOTE that the parentheses in the second expression should never be
> > omitted, a possible reason to prefer the as.logical() construction.
> > Also note that !!  "acts [only] on raw, logical and number-like
> > vectors," whereas as.logical() is more general. e.g. (from ?logical):
> >
> > > charvec <- c("FALSE", "F", "False", "false","fAlse", "0",
> > +  "TRUE",  "T", "True",  "true", "tRue",  "1")
> > > as.logical(charvec)
> >  [1] FALSE FALSE FALSE FALSENANA  TRUE  TRUE  TRUE  TRUENA
> >NA
> > > !!charvec
> > Error in !charvec : invalid argument type
> >
> >
> > Cheers,
> > Bert
> >
> > 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 Wed, Jun 23, 2021 at 8:31 AM Eric Berger  > > wrote:
> >
> > In my code, instead of 't', I name a vector of indices with a
> > meaningful
> > name, such as idxV, to make it obvious.
> >
> > Alternatively, a minor change in your style would be to replace your
> > definition of t by
> >
> > t <- as.logical(c(1,1,1,0,0))
> >
> > HTH,
> > Eric
> >
> >
> > On Wed, Jun 23, 2021 at 6:11 PM Phillips Rogfield
> > mailto:thebudge...@gmail.com>>
> > wrote:
> >
> > > I make the same mistake all over again.
> > >
> > > In particular, suppose we have:
> > >
> > > a = c(1,2,3,4,5)
> > >
> > > and a variable that equals 1 for the elements I want to select:
> > >
> > > t = c(1,1,1,0,0)
> > >
> > > To select the first 3 elements.
> > >
> > > The problem is that
> > >
> > > a[t]
> > >
> > > would repeat the first element 3 times .
> > >
> > > I have to either convert `t` to boolean:
> > >
> > > a[t==1]
> > >
> > > Or use `which`
> > >
> > > a[which(t==1)]
> > >
> > > How can I "spot" this error?
> > >
> > > It often happens in long scripts.
> > >
> > > Do I have to check the type each time?
> > >
> > > Do you have any suggestions?
> > >
> > > __
> > > 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.
> >
>
> [[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] Special characters in cell names

2021-06-23 Thread Bert Gunter
I found your specification quite vague. What did you mean by a "data file"
-- a data frame in R? -- a file in the file system?

I may be completely wrong here, but another possibility is that you read
your data into an R data.frame via, e.g. read.table() or read.csv(), but
failed to specify the check.names = FALSE, argument. This would cause a
column named "x/y" in your original table to be given the name "x.y" in R,
as "x/y" is not a syntactically valid name. See ?make.names for details.

As others have already said, enclosing non-syntactically valid names in
back ticks usually works (maybe always works??). So for example:

z<-data.frame (`a/b` = 1:5, y = 1:5, check.names = FALSE)
plot(y ~ `a/b`, data = z) ## produces desired plot with correct label
z  ## yields:
  a/b y
1   1 1
2   2 2
3   3 3
4   4 4
5   5 5

Of course, ignore if this is all irrelevant.

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 Wed, Jun 23, 2021 at 1:37 PM Mahmood Naderan 
wrote:

> Unfortunately, using 'X/Y' doesn't work either.
> Instead I used labels like below
>
> P + scale_y_continuous(name="X/Y")
>
> Thanks for the suggestions.
>
> Regards,
> Mahmood
>
>
>
>
> On Wed, Jun 23, 2021 at 9:22 PM Eric Berger  wrote:
>
> > If no one comes up with a better suggestion:
> > a. Change the column name to "Y" so that you get the plot you want
> > b. Use axis labels and legend text to show the text that you want. (The
> > user never has to know that you changed the column name )
> >
> > HTH,
> > Eric
> >
> > On Wed, Jun 23, 2021 at 9:58 PM Mahmood Naderan 
> > wrote:
> >
> >> Hi
> >> I have a column in my data file which is "X/Y". With '/' I want to
> >> emphasize that values are the ratio of X over Y.
> >> Problem is that in the following command for a violin plot, I am not
> able
> >> to specify that '/' even with double quotes.
> >>
> >> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
> >>
> >> However, if I change that column to "Y" and use
> >>
> >> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
> >>
> >> Then the plot will be correctly shown.
> >> Any ideas for that?
> >>
> >> Regards,
> >> Mahmood
> >>
> >> [[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.
>

[[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] Special characters in cell names

2021-06-23 Thread Mahmood Naderan
Unfortunately, using 'X/Y' doesn't work either.
Instead I used labels like below

P + scale_y_continuous(name="X/Y")

Thanks for the suggestions.

Regards,
Mahmood




On Wed, Jun 23, 2021 at 9:22 PM Eric Berger  wrote:

> If no one comes up with a better suggestion:
> a. Change the column name to "Y" so that you get the plot you want
> b. Use axis labels and legend text to show the text that you want. (The
> user never has to know that you changed the column name )
>
> HTH,
> Eric
>
> On Wed, Jun 23, 2021 at 9:58 PM Mahmood Naderan 
> wrote:
>
>> Hi
>> I have a column in my data file which is "X/Y". With '/' I want to
>> emphasize that values are the ratio of X over Y.
>> Problem is that in the following command for a violin plot, I am not able
>> to specify that '/' even with double quotes.
>>
>> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
>>
>> However, if I change that column to "Y" and use
>>
>> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
>>
>> Then the plot will be correctly shown.
>> Any ideas for that?
>>
>> Regards,
>> Mahmood
>>
>> [[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] How to spot/stop making the same mistake

2021-06-23 Thread Jeff Newmiller
IMO that puts the cart before the horse. rlang implements these "operators" in 
very focused situations using custom expression parsing, and if they cannot 
tell the difference between numeric/logical and character data then rlang is 
broken.

That said, I do think as.logical() is more direct than !! for this purpose.

On June 23, 2021 11:27:38 AM PDT, Bill Dunlap  wrote:
>Note that !! and !!! are special operators involving "quasiquotation"
>in
>the dplyr package.
>
>I would use as.logical(x) instead of !!x since its meaning is clear to
>any
>user.
>
>-Bill
>
>On Wed, Jun 23, 2021 at 11:13 AM Jeff Newmiller
>
>wrote:
>
>> For the record, `!!` is not an operator so it does not "operate" on
>> anything. The right ! does per the help page (?`!`) interpret
>non-zero
>> values as TRUE and invert that logic, yielding a logical result even
>if the
>> input is not logical. The left ! inverts that again, yielding a
>logical
>> vector without the inversion.
>>
>> On June 23, 2021 10:39:07 AM PDT, Phillips Rogfield
>
>> wrote:
>> >Dear all,
>> >
>> >thank for for your suggestion.
>> >
>> >Yes I come from languages where 1 means TRUE and 0 means FALSE. In
>> >particular from C/C++ and Python.
>> >
>> >Evidently this is not the case for R.
>> >
>> >In my mind I kind took for granted that that was the case (1=TRUE,
>> >0=FALSE).
>> >
>> >Knowing this is not the case for R makes things simpler.
>> >
>> >Mine was just an example, sometimes I load datasets taken from
>outside
>> >and variables are coded with 1/0 (for example, a treatment variable
>may
>> >
>> >be coded that way).
>> >
>> >I also did not know the !!() syntax!
>> >
>> >Thank you for your help and best regards.
>> >
>> >On 23/06/2021 17:55, Bert Gunter wrote:
>> >> Just as a way to save a bit of typing, instead of
>> >>
>> >> > as.logical(0:4)
>> >> [1] FALSE  TRUE  TRUE  TRUE  TRUE
>> >>
>> >> > !!(0:4)
>> >> [1] FALSE  TRUE  TRUE  TRUE  TRUE
>> >>
>> >> DO NOTE that the parentheses in the second expression should never
>be
>> >
>> >> omitted, a possible reason to prefer the as.logical()
>construction.
>> >> Also note that !!  "acts [only] on raw, logical and number-like
>> >> vectors," whereas as.logical() is more general. e.g. (from
>?logical):
>> >>
>> >> > charvec <- c("FALSE", "F", "False", "false","fAlse", "0",
>> >> +  "TRUE",  "T", "True",  "true", "tRue",  "1")
>> >> > as.logical(charvec)
>> >>  [1] FALSE FALSE FALSE FALSENANA  TRUE  TRUE  TRUE  TRUE
>> > NA
>> >>NA
>> >> > !!charvec
>> >> Error in !charvec : invalid argument type
>> >>
>> >>
>> >> Cheers,
>> >> Bert
>> >>
>> >> 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 Wed, Jun 23, 2021 at 8:31 AM Eric Berger > >> > wrote:
>> >>
>> >> In my code, instead of 't', I name a vector of indices with a
>> >> meaningful
>> >> name, such as idxV, to make it obvious.
>> >>
>> >> Alternatively, a minor change in your style would be to
>replace
>> >your
>> >> definition of t by
>> >>
>> >> t <- as.logical(c(1,1,1,0,0))
>> >>
>> >> HTH,
>> >> Eric
>> >>
>> >>
>> >> On Wed, Jun 23, 2021 at 6:11 PM Phillips Rogfield
>> >> mailto:thebudge...@gmail.com>>
>> >> wrote:
>> >>
>> >> > I make the same mistake all over again.
>> >> >
>> >> > In particular, suppose we have:
>> >> >
>> >> > a = c(1,2,3,4,5)
>> >> >
>> >> > and a variable that equals 1 for the elements I want to
>select:
>> >> >
>> >> > t = c(1,1,1,0,0)
>> >> >
>> >> > To select the first 3 elements.
>> >> >
>> >> > The problem is that
>> >> >
>> >> > a[t]
>> >> >
>> >> > would repeat the first element 3 times .
>> >> >
>> >> > I have to either convert `t` to boolean:
>> >> >
>> >> > a[t==1]
>> >> >
>> >> > Or use `which`
>> >> >
>> >> > a[which(t==1)]
>> >> >
>> >> > How can I "spot" this error?
>> >> >
>> >> > It often happens in long scripts.
>> >> >
>> >> > Do I have to check the type each time?
>> >> >
>> >> > Do you have any suggestions?
>> >> >
>> >> > __
>> >> > 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]]
>> >>
>> >> __
>> >> 

Re: [R] Special characters in cell names

2021-06-23 Thread Eric Berger
If no one comes up with a better suggestion:
a. Change the column name to "Y" so that you get the plot you want
b. Use axis labels and legend text to show the text that you want. (The
user never has to know that you changed the column name )

HTH,
Eric

On Wed, Jun 23, 2021 at 9:58 PM Mahmood Naderan 
wrote:

> Hi
> I have a column in my data file which is "X/Y". With '/' I want to
> emphasize that values are the ratio of X over Y.
> Problem is that in the following command for a violin plot, I am not able
> to specify that '/' even with double quotes.
>
> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
>
> However, if I change that column to "Y" and use
>
> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
>
> Then the plot will be correctly shown.
> Any ideas for that?
>
> Regards,
> Mahmood
>
> [[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] interactively getting alist of functions for a given package?

2021-06-23 Thread Duncan Murdoch

On 23/06/2021 2:51 p.m., Jeff Newmiller wrote:

RStudio seems to have done this. If you have it, try typing

ggplot2::line

and the popup will suggest (among other options) geom_line.


Yes, though it may not be quite right.  Back in May when I typed

 library(rgl

their autocompletion gave me

 library(Rglpk)

(See https://github.com/rstudio/rstudio/issues/9293).  Today that's not 
happening, so maybe it's been fixed, or is only intermittent.


Duncan Murdoch





On June 23, 2021 10:10:07 AM PDT, Duncan Murdoch  
wrote:

On 23/06/2021 8:37 a.m., Greg Minshall wrote:

hi.

at the R prompt, i often hit, e.g., "data.table::", to try to

find

a routine in a give package.

however, some packages have a *lot* of functions (i'm looking at

*you*,

ggplot2...), so if i know the routine name starts with, e.g., "set",

i

can filter the returned list of routines by typing
"data.table::set" to get a list of completions.

but, what if i know the name *contains*, but doesn't start with,

"set"?


is there an obvious way to find this?  something like the unix-y
: ls /bin | grep -i "set"


Bert gave you an answer that depends on ls().  Whether there's
something
like "set" that can return "asset" probably depends on your front
end, and may be customizable using the facilities described in
?rcompgen.

Duncan Murdoch

__
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] Wayland backend for R

2021-06-23 Thread Phillips Rogfield
Dear Robert,

Thank you very much for your suggestion.

I solved by compiling R with --with-cairo, and installing cairo-devel 
and pango-devel.

Notably, you also need pango-devel.

The configure script does not complain if it is missing, but then 
plotting won't work.

Best regards.

On 23/06/2021 20:26, Robert Knight wrote:
> Perhaps software rendering would work.
>
> |Export RSTUDIO_CHROMIUM_ARGUMENTS="--disable-gpu"|
> |/usr/lib/rstudio/bin/rstudio|
>
> On Wed, Jun 23, 2021, 10:01 AM Phillips Rogfield 
> mailto:thebudge...@gmail.com>> wrote:
>
> Hello Paul,
>
> thank you for your kind advice.
>
> RStudio doesn't start at all this way. It gives me the following
> error:
>
> $ QT_QPA_PLATFORM=wayland rstudio
> Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use
> QT_QPA_PLATFORM=wayland to run on Wayland anyway.
> QSocketNotifier: Can only be used with threads started with QThread
> Failed to load client buffer integration: wayland-egl
>
> WebEngineContext used before QtWebEngine::initialize() or OpenGL
> context
> creation failed.
> qt.qpa.wayland: No shell integration named "xdg-shell" found
> qt.qpa.wayland: No shell integration named "xdg-shell-v6" found
> qt.qpa.wayland: No shell integration named "wl-shell" found
> qt.qpa.wayland: No shell integration named "ivi-shell" found
> qt.qpa.wayland: Loading shell integration failed.
> qt.qpa.wayland: Attempted to load the following shells ("xdg-shell",
> "xdg-shell-v6", "wl-shell", "ivi-shell")
> qt.qpa.wayland: Wayland does not support QWindow::requestActivate()
>
> Best regards.
>
> On 23/06/2021 02:22, Paul Murrell wrote:
> > Hi
> >
> > I do not know of any Wayland backend for R.
> >
> > You might be able to try the R Studio IDE configured for Wayland
> and
> > see how its graphics device performs ?
> > https://github.com/rstudio/rstudio/issues/4686
> 
> >
> > Paul
> >
> > On 23/06/21 1:25 am, Phillips Rogfield wrote:
> >> I have compiled R from source and I had to install the X11
> libraries.
> >>
> >> I use Wayland, and I am having problems plotting on X11 (I
> guess it uses
> >> XWayland) with this version.
> >>
> >> Is there a Wayland backend for R?
> >>
> >> Some configuration option I need to turn on in order to use it?
> >>
> >> __
> >> 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.
>

[[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] Special characters in cell names

2021-06-23 Thread Duncan Murdoch

On 23/06/2021 11:38 a.m., Mahmood Naderan wrote:

Hi
I have a column in my data file which is "X/Y". With '/' I want to
emphasize that values are the ratio of X over Y.
Problem is that in the following command for a violin plot, I am not able
to specify that '/' even with double quotes.

p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)

However, if I change that column to "Y" and use

p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)

Then the plot will be correctly shown.
Any ideas for that?


I haven't tried, but I'd expect back quotes would work:


ggplot(mydata, aes(x=W, y=`X/Y`))


That's the normal way to quote a name in R.

Duncan Murdoch

__
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] Special characters in cell names

2021-06-23 Thread Bill Dunlap
Use backquotes, `X/Y`, to specify a name, not double quotes.

-Bill

On Wed, Jun 23, 2021 at 11:58 AM Mahmood Naderan 
wrote:

> Hi
> I have a column in my data file which is "X/Y". With '/' I want to
> emphasize that values are the ratio of X over Y.
> Problem is that in the following command for a violin plot, I am not able
> to specify that '/' even with double quotes.
>
> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
>
> However, if I change that column to "Y" and use
>
> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
>
> Then the plot will be correctly shown.
> Any ideas for that?
>
> Regards,
> Mahmood
>
> [[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.


[R] Special characters in cell names

2021-06-23 Thread Mahmood Naderan
Hi
I have a column in my data file which is "X/Y". With '/' I want to
emphasize that values are the ratio of X over Y.
Problem is that in the following command for a violin plot, I am not able
to specify that '/' even with double quotes.

p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)

However, if I change that column to "Y" and use

p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)

Then the plot will be correctly shown.
Any ideas for that?

Regards,
Mahmood

[[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] interactively getting alist of functions for a given package?

2021-06-23 Thread Jeff Newmiller
RStudio seems to have done this. If you have it, try typing

ggplot2::line

and the popup will suggest (among other options) geom_line.

On June 23, 2021 10:10:07 AM PDT, Duncan Murdoch  
wrote:
>On 23/06/2021 8:37 a.m., Greg Minshall wrote:
>> hi.
>> 
>> at the R prompt, i often hit, e.g., "data.table::", to try to
>find
>> a routine in a give package.
>> 
>> however, some packages have a *lot* of functions (i'm looking at
>*you*,
>> ggplot2...), so if i know the routine name starts with, e.g., "set",
>i
>> can filter the returned list of routines by typing
>> "data.table::set" to get a list of completions.
>> 
>> but, what if i know the name *contains*, but doesn't start with,
>"set"?
>> 
>> is there an obvious way to find this?  something like the unix-y
>> : ls /bin | grep -i "set"
>
>Bert gave you an answer that depends on ls().  Whether there's
>something 
>like "set" that can return "asset" probably depends on your front 
>end, and may be customizable using the facilities described in
>?rcompgen.
>
>Duncan Murdoch
>
>__
>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] Plot NUTS regions with color

2021-06-23 Thread Bert Gunter
I suggest you post this in the r-sig-geo list rather than here. The
expertise you seek is more likely to be there.

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 Wed, Jun 23, 2021 at 10:36 AM Phillips Rogfield 
wrote:

> Dear R-help ML,
>
> I have downloaded the NUTS shapefiles from here:
>
> https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts
>
> I can load them with the following code:
>
> library(rgdal)
> shp_bdir <- [PATH TO SHAPE FILE]
> layername <- "NUTS_RG_01M_2021_4326"
> shp_folder <- file.path(shp_bdir, paste0(layername,".shp"))
> EU_NUTS <- readOGR(dsn = shp_folder, layer = layername)
>
> Then I can plot the regions with:
>
> plot(EU_NUTS)
>
> Now I have a list of NUTS - 3 Level, for example:
>
> l <- c("AT223", "AT212", "AT212", "AT121")
>
> I would like a plot where the NUTS regions are colored, and the more a
> particular NUTS is present is the list, the darker its color.
>
> For example "AT212" should be darker than "AT223", because the former is
> present two times in the list.
>
> How can I achieve that?
>
> Thank you and best regards.
>
>
> [[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] How to spot/stop making the same mistake

2021-06-23 Thread Bill Dunlap
Note that !! and !!! are special operators involving "quasiquotation" in
the dplyr package.

I would use as.logical(x) instead of !!x since its meaning is clear to any
user.

-Bill

On Wed, Jun 23, 2021 at 11:13 AM Jeff Newmiller 
wrote:

> For the record, `!!` is not an operator so it does not "operate" on
> anything. The right ! does per the help page (?`!`) interpret non-zero
> values as TRUE and invert that logic, yielding a logical result even if the
> input is not logical. The left ! inverts that again, yielding a logical
> vector without the inversion.
>
> On June 23, 2021 10:39:07 AM PDT, Phillips Rogfield 
> wrote:
> >Dear all,
> >
> >thank for for your suggestion.
> >
> >Yes I come from languages where 1 means TRUE and 0 means FALSE. In
> >particular from C/C++ and Python.
> >
> >Evidently this is not the case for R.
> >
> >In my mind I kind took for granted that that was the case (1=TRUE,
> >0=FALSE).
> >
> >Knowing this is not the case for R makes things simpler.
> >
> >Mine was just an example, sometimes I load datasets taken from outside
> >and variables are coded with 1/0 (for example, a treatment variable may
> >
> >be coded that way).
> >
> >I also did not know the !!() syntax!
> >
> >Thank you for your help and best regards.
> >
> >On 23/06/2021 17:55, Bert Gunter wrote:
> >> Just as a way to save a bit of typing, instead of
> >>
> >> > as.logical(0:4)
> >> [1] FALSE  TRUE  TRUE  TRUE  TRUE
> >>
> >> > !!(0:4)
> >> [1] FALSE  TRUE  TRUE  TRUE  TRUE
> >>
> >> DO NOTE that the parentheses in the second expression should never be
> >
> >> omitted, a possible reason to prefer the as.logical() construction.
> >> Also note that !!  "acts [only] on raw, logical and number-like
> >> vectors," whereas as.logical() is more general. e.g. (from ?logical):
> >>
> >> > charvec <- c("FALSE", "F", "False", "false","fAlse", "0",
> >> +  "TRUE",  "T", "True",  "true", "tRue",  "1")
> >> > as.logical(charvec)
> >>  [1] FALSE FALSE FALSE FALSENANA  TRUE  TRUE  TRUE  TRUE
> > NA
> >>NA
> >> > !!charvec
> >> Error in !charvec : invalid argument type
> >>
> >>
> >> Cheers,
> >> Bert
> >>
> >> 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 Wed, Jun 23, 2021 at 8:31 AM Eric Berger  >> > wrote:
> >>
> >> In my code, instead of 't', I name a vector of indices with a
> >> meaningful
> >> name, such as idxV, to make it obvious.
> >>
> >> Alternatively, a minor change in your style would be to replace
> >your
> >> definition of t by
> >>
> >> t <- as.logical(c(1,1,1,0,0))
> >>
> >> HTH,
> >> Eric
> >>
> >>
> >> On Wed, Jun 23, 2021 at 6:11 PM Phillips Rogfield
> >> mailto:thebudge...@gmail.com>>
> >> wrote:
> >>
> >> > I make the same mistake all over again.
> >> >
> >> > In particular, suppose we have:
> >> >
> >> > a = c(1,2,3,4,5)
> >> >
> >> > and a variable that equals 1 for the elements I want to select:
> >> >
> >> > t = c(1,1,1,0,0)
> >> >
> >> > To select the first 3 elements.
> >> >
> >> > The problem is that
> >> >
> >> > a[t]
> >> >
> >> > would repeat the first element 3 times .
> >> >
> >> > I have to either convert `t` to boolean:
> >> >
> >> > a[t==1]
> >> >
> >> > Or use `which`
> >> >
> >> > a[which(t==1)]
> >> >
> >> > How can I "spot" this error?
> >> >
> >> > It often happens in long scripts.
> >> >
> >> > Do I have to check the type each time?
> >> >
> >> > Do you have any suggestions?
> >> >
> >> > __
> >> > 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.
> >>
> >
> >   [[alternative HTML version deleted]]
> >
> 

Re: [R] Wayland backend for R

2021-06-23 Thread Robert Knight
Perhaps software rendering would work.

Export RSTUDIO_CHROMIUM_ARGUMENTS="--disable-gpu"

/usr/lib/rstudio/bin/rstudio


On Wed, Jun 23, 2021, 10:01 AM Phillips Rogfield 
wrote:

> Hello Paul,
>
> thank you for your kind advice.
>
> RStudio doesn't start at all this way. It gives me the following error:
>
> $ QT_QPA_PLATFORM=wayland rstudio
> Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use
> QT_QPA_PLATFORM=wayland to run on Wayland anyway.
> QSocketNotifier: Can only be used with threads started with QThread
> Failed to load client buffer integration: wayland-egl
>
> WebEngineContext used before QtWebEngine::initialize() or OpenGL context
> creation failed.
> qt.qpa.wayland: No shell integration named "xdg-shell" found
> qt.qpa.wayland: No shell integration named "xdg-shell-v6" found
> qt.qpa.wayland: No shell integration named "wl-shell" found
> qt.qpa.wayland: No shell integration named "ivi-shell" found
> qt.qpa.wayland: Loading shell integration failed.
> qt.qpa.wayland: Attempted to load the following shells ("xdg-shell",
> "xdg-shell-v6", "wl-shell", "ivi-shell")
> qt.qpa.wayland: Wayland does not support QWindow::requestActivate()
>
> Best regards.
>
> On 23/06/2021 02:22, Paul Murrell wrote:
> > Hi
> >
> > I do not know of any Wayland backend for R.
> >
> > You might be able to try the R Studio IDE configured for Wayland and
> > see how its graphics device performs ?
> > https://github.com/rstudio/rstudio/issues/4686
> >
> > Paul
> >
> > On 23/06/21 1:25 am, Phillips Rogfield wrote:
> >> I have compiled R from source and I had to install the X11 libraries.
> >>
> >> I use Wayland, and I am having problems plotting on X11 (I guess it uses
> >> XWayland) with this version.
> >>
> >> Is there a Wayland backend for R?
> >>
> >> Some configuration option I need to turn on in order to use it?
> >>
> >> __
> >> 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.
>

[[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] How to spot/stop making the same mistake

2021-06-23 Thread Jeff Newmiller
For the record, `!!` is not an operator so it does not "operate" on anything. 
The right ! does per the help page (?`!`) interpret non-zero values as TRUE and 
invert that logic, yielding a logical result even if the input is not logical. 
The left ! inverts that again, yielding a logical vector without the inversion.

On June 23, 2021 10:39:07 AM PDT, Phillips Rogfield  
wrote:
>Dear all,
>
>thank for for your suggestion.
>
>Yes I come from languages where 1 means TRUE and 0 means FALSE. In 
>particular from C/C++ and Python.
>
>Evidently this is not the case for R.
>
>In my mind I kind took for granted that that was the case (1=TRUE,
>0=FALSE).
>
>Knowing this is not the case for R makes things simpler.
>
>Mine was just an example, sometimes I load datasets taken from outside 
>and variables are coded with 1/0 (for example, a treatment variable may
>
>be coded that way).
>
>I also did not know the !!() syntax!
>
>Thank you for your help and best regards.
>
>On 23/06/2021 17:55, Bert Gunter wrote:
>> Just as a way to save a bit of typing, instead of
>>
>> > as.logical(0:4)
>> [1] FALSE  TRUE  TRUE  TRUE  TRUE
>>
>> > !!(0:4)
>> [1] FALSE  TRUE  TRUE  TRUE  TRUE
>>
>> DO NOTE that the parentheses in the second expression should never be
>
>> omitted, a possible reason to prefer the as.logical() construction.
>> Also note that !!  "acts [only] on raw, logical and number-like 
>> vectors," whereas as.logical() is more general. e.g. (from ?logical):
>>
>> > charvec <- c("FALSE", "F", "False", "false",    "fAlse", "0",
>> +              "TRUE",  "T", "True",  "true",     "tRue",  "1")
>> > as.logical(charvec)
>>  [1] FALSE FALSE FALSE FALSE    NA    NA  TRUE  TRUE  TRUE  TRUE  
> NA 
>>    NA
>> > !!charvec
>> Error in !charvec : invalid argument type
>>
>>
>> Cheers,
>> Bert
>>
>> 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 Wed, Jun 23, 2021 at 8:31 AM Eric Berger > > wrote:
>>
>> In my code, instead of 't', I name a vector of indices with a
>> meaningful
>> name, such as idxV, to make it obvious.
>>
>> Alternatively, a minor change in your style would be to replace
>your
>> definition of t by
>>
>> t <- as.logical(c(1,1,1,0,0))
>>
>> HTH,
>> Eric
>>
>>
>> On Wed, Jun 23, 2021 at 6:11 PM Phillips Rogfield
>> mailto:thebudge...@gmail.com>>
>> wrote:
>>
>> > I make the same mistake all over again.
>> >
>> > In particular, suppose we have:
>> >
>> > a = c(1,2,3,4,5)
>> >
>> > and a variable that equals 1 for the elements I want to select:
>> >
>> > t = c(1,1,1,0,0)
>> >
>> > To select the first 3 elements.
>> >
>> > The problem is that
>> >
>> > a[t]
>> >
>> > would repeat the first element 3 times .
>> >
>> > I have to either convert `t` to boolean:
>> >
>> > a[t==1]
>> >
>> > Or use `which`
>> >
>> > a[which(t==1)]
>> >
>> > How can I "spot" this error?
>> >
>> > It often happens in long scripts.
>> >
>> > Do I have to check the type each time?
>> >
>> > Do you have any suggestions?
>> >
>> > __
>> > 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.
>>
>
>   [[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 

[R] Mean absolute error from data matrix

2021-06-23 Thread Faheem Jan via R-help
I have data matrix of order 24*2192 where 2192 are the days and 24 are hour's 
of a single day,so simple words I have 2192 days and each day having 24 
observations.the data matrix is divided into two matrix,the ist matrix is of 
order 24*1827 and second is of order 24*365. Suppose the ist column of the 
second matrix is Sunday then we choose each column of the first matrix having 
Sunday. The takeing the first column of data matrix is converted into vector 
and all the Sunday columns are converted into vectors. Then we calculate mean 
absolute errors for different pairs of the first vector of the second matrix 
with each vector of first matrix. Similarly process is repeated for the rest of 
the week days. It clear that such process is quite time consuming and hard if 
perform manually. Can any one provides the easiest way to do such 
problem.Regard 

Sent from Yahoo Mail on Android
[[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] How to spot/stop making the same mistake

2021-06-23 Thread Phillips Rogfield
Dear all,

thank for for your suggestion.

Yes I come from languages where 1 means TRUE and 0 means FALSE. In 
particular from C/C++ and Python.

Evidently this is not the case for R.

In my mind I kind took for granted that that was the case (1=TRUE, 0=FALSE).

Knowing this is not the case for R makes things simpler.

Mine was just an example, sometimes I load datasets taken from outside 
and variables are coded with 1/0 (for example, a treatment variable may 
be coded that way).

I also did not know the !!() syntax!

Thank you for your help and best regards.

On 23/06/2021 17:55, Bert Gunter wrote:
> Just as a way to save a bit of typing, instead of
>
> > as.logical(0:4)
> [1] FALSE  TRUE  TRUE  TRUE  TRUE
>
> > !!(0:4)
> [1] FALSE  TRUE  TRUE  TRUE  TRUE
>
> DO NOTE that the parentheses in the second expression should never be 
> omitted, a possible reason to prefer the as.logical() construction.
> Also note that !!  "acts [only] on raw, logical and number-like 
> vectors," whereas as.logical() is more general. e.g. (from ?logical):
>
> > charvec <- c("FALSE", "F", "False", "false",    "fAlse", "0",
> +              "TRUE",  "T", "True",  "true",     "tRue",  "1")
> > as.logical(charvec)
>  [1] FALSE FALSE FALSE FALSE    NA    NA  TRUE  TRUE  TRUE  TRUE    NA 
>    NA
> > !!charvec
> Error in !charvec : invalid argument type
>
>
> Cheers,
> Bert
>
> 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 Wed, Jun 23, 2021 at 8:31 AM Eric Berger  > wrote:
>
> In my code, instead of 't', I name a vector of indices with a
> meaningful
> name, such as idxV, to make it obvious.
>
> Alternatively, a minor change in your style would be to replace your
> definition of t by
>
> t <- as.logical(c(1,1,1,0,0))
>
> HTH,
> Eric
>
>
> On Wed, Jun 23, 2021 at 6:11 PM Phillips Rogfield
> mailto:thebudge...@gmail.com>>
> wrote:
>
> > I make the same mistake all over again.
> >
> > In particular, suppose we have:
> >
> > a = c(1,2,3,4,5)
> >
> > and a variable that equals 1 for the elements I want to select:
> >
> > t = c(1,1,1,0,0)
> >
> > To select the first 3 elements.
> >
> > The problem is that
> >
> > a[t]
> >
> > would repeat the first element 3 times .
> >
> > I have to either convert `t` to boolean:
> >
> > a[t==1]
> >
> > Or use `which`
> >
> > a[which(t==1)]
> >
> > How can I "spot" this error?
> >
> > It often happens in long scripts.
> >
> > Do I have to check the type each time?
> >
> > Do you have any suggestions?
> >
> > __
> > 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.
>

[[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] Plot NUTS regions with color

2021-06-23 Thread Phillips Rogfield
Dear R-help ML,

I have downloaded the NUTS shapefiles from here: 
https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts

I can load them with the following code:

library(rgdal)
shp_bdir <- [PATH TO SHAPE FILE]
layername <- "NUTS_RG_01M_2021_4326"
shp_folder <- file.path(shp_bdir, paste0(layername,".shp"))
EU_NUTS <- readOGR(dsn = shp_folder, layer = layername)

Then I can plot the regions with:

plot(EU_NUTS)

Now I have a list of NUTS - 3 Level, for example:

l <- c("AT223", "AT212", "AT212", "AT121")

I would like a plot where the NUTS regions are colored, and the more a 
particular NUTS is present is the list, the darker its color.

For example "AT212" should be darker than "AT223", because the former is 
present two times in the list.

How can I achieve that?

Thank you and best regards.


[[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] interactively getting alist of functions for a given package?

2021-06-23 Thread Duncan Murdoch

On 23/06/2021 8:37 a.m., Greg Minshall wrote:

hi.

at the R prompt, i often hit, e.g., "data.table::", to try to find
a routine in a give package.

however, some packages have a *lot* of functions (i'm looking at *you*,
ggplot2...), so if i know the routine name starts with, e.g., "set", i
can filter the returned list of routines by typing
"data.table::set" to get a list of completions.

but, what if i know the name *contains*, but doesn't start with, "set"?

is there an obvious way to find this?  something like the unix-y
: ls /bin | grep -i "set"


Bert gave you an answer that depends on ls().  Whether there's something 
like "set" that can return "asset" probably depends on your front 
end, and may be customizable using the facilities described in ?rcompgen.


Duncan Murdoch

__
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] How to spot/stop making the same mistake

2021-06-23 Thread Bert Gunter
Just as a way to save a bit of typing, instead of

> as.logical(0:4)
[1] FALSE  TRUE  TRUE  TRUE  TRUE

> !!(0:4)
[1] FALSE  TRUE  TRUE  TRUE  TRUE

DO NOTE that the parentheses in the second expression should never be
omitted, a possible reason to prefer the as.logical() construction.
Also note that !!  "acts [only] on raw, logical and number-like vectors,"
whereas as.logical() is more general. e.g. (from ?logical):

> charvec <- c("FALSE", "F", "False", "false","fAlse", "0",
+  "TRUE",  "T", "True",  "true", "tRue",  "1")
> as.logical(charvec)
 [1] FALSE FALSE FALSE FALSENANA  TRUE  TRUE  TRUE  TRUENANA
> !!charvec
Error in !charvec : invalid argument type


Cheers,
Bert

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 Wed, Jun 23, 2021 at 8:31 AM Eric Berger  wrote:

> In my code, instead of 't', I name a vector of indices with a meaningful
> name, such as idxV, to make it obvious.
>
> Alternatively, a minor change in your style would be to replace your
> definition of t by
>
> t <- as.logical(c(1,1,1,0,0))
>
> HTH,
> Eric
>
>
> On Wed, Jun 23, 2021 at 6:11 PM Phillips Rogfield 
> wrote:
>
> > I make the same mistake all over again.
> >
> > In particular, suppose we have:
> >
> > a = c(1,2,3,4,5)
> >
> > and a variable that equals 1 for the elements I want to select:
> >
> > t = c(1,1,1,0,0)
> >
> > To select the first 3 elements.
> >
> > The problem is that
> >
> > a[t]
> >
> > would repeat the first element 3 times .
> >
> > I have to either convert `t` to boolean:
> >
> > a[t==1]
> >
> > Or use `which`
> >
> > a[which(t==1)]
> >
> > How can I "spot" this error?
> >
> > It often happens in long scripts.
> >
> > Do I have to check the type each time?
> >
> > Do you have any suggestions?
> >
> > __
> > 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.
>

[[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] How to spot/stop making the same mistake

2021-06-23 Thread Avi Gross via R-help
This is unfortunately a bad habit many of us got from earlier languages like
the C group of languages where 0 is FALSE and 1 (and anything non-zero) is
TRUE. A language like Python is arguably even worse in that all kinds of
things can be TRUE or FALSE in odd ways, like a non-empty string or even a
random object which has declared how to decide if it qualifies as true.

R here has an issue with having so many ways to index a vector so that use
of integers has another meaning and only indexing by Booleans has the
meaning you want. So, you just need to adjust your mindset or perhaps write
a little silly function like ensure_boolean() that checks if the vector it
has is ALL just full of zero or 1 with probably no NA and otherwise returns
the vector unchanged. If it is all 0/1, it converts it and returns the
Boolean equivalent. Then instead of supplying the vector directly, most of
the time, you can substitute ensure_boolean(vec) 


-Original Message-
From: R-help  On Behalf Of Jeff Newmiller
Sent: Wednesday, June 23, 2021 11:18 AM
To: r-help@r-project.org; Phillips Rogfield ;
r-help@r-project.org
Subject: Re: [R] How to spot/stop making the same mistake

I practically never construct vectors like your `t` so it isn't a problem.
And since I make a habit of verifying the types of all vectors I am using in
expressions, if it did come up I would notice.

On June 23, 2021 8:06:05 AM PDT, Phillips Rogfield 
wrote:
>I make the same mistake all over again.
>
>In particular, suppose we have:
>
>a = c(1,2,3,4,5)
>
>and a variable that equals 1 for the elements I want to select:
>
>t = c(1,1,1,0,0)
>
>To select the first 3 elements.
>
>The problem is that
>
>a[t]
>
>would repeat the first element 3 times .
>
>I have to either convert `t` to boolean:
>
>a[t==1]
>
>Or use `which`
>
>a[which(t==1)]
>
>How can I "spot" this error?
>
>It often happens in long scripts.
>
>Do I have to check the type each time?
>
>Do you have any suggestions?
>
>__
>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.

__
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] How to spot/stop making the same mistake

2021-06-23 Thread Bill Dunlap
> a variable that equals 1 for the elements I want to select:
>
> t = c(1,1,1,0,0)

How do you typically make such a variable?   If you use something like
   t <- ifelse(x == "Yes", 1, 0)
you should instead use
   t <- x == "Yes"

Naming the variable something like 'isYes' instead of 't' might help as
well.

-Bill

On Wed, Jun 23, 2021 at 8:11 AM Phillips Rogfield 
wrote:

> I make the same mistake all over again.
>
> In particular, suppose we have:
>
> a = c(1,2,3,4,5)
>
> and a variable that equals 1 for the elements I want to select:
>
> t = c(1,1,1,0,0)
>
> To select the first 3 elements.
>
> The problem is that
>
> a[t]
>
> would repeat the first element 3 times .
>
> I have to either convert `t` to boolean:
>
> a[t==1]
>
> Or use `which`
>
> a[which(t==1)]
>
> How can I "spot" this error?
>
> It often happens in long scripts.
>
> Do I have to check the type each time?
>
> Do you have any suggestions?
>
> __
> 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] interactively getting alist of functions for a given package?

2021-06-23 Thread Greg Minshall
Bert,

> ?ls  and note the "pattern" argument.
...
> ls("package:base", pat =".*set.*")

awesome -- thanks!

cheers, Greg

__
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] How to spot/stop making the same mistake

2021-06-23 Thread Eric Berger
In my code, instead of 't', I name a vector of indices with a meaningful
name, such as idxV, to make it obvious.

Alternatively, a minor change in your style would be to replace your
definition of t by

t <- as.logical(c(1,1,1,0,0))

HTH,
Eric


On Wed, Jun 23, 2021 at 6:11 PM Phillips Rogfield 
wrote:

> I make the same mistake all over again.
>
> In particular, suppose we have:
>
> a = c(1,2,3,4,5)
>
> and a variable that equals 1 for the elements I want to select:
>
> t = c(1,1,1,0,0)
>
> To select the first 3 elements.
>
> The problem is that
>
> a[t]
>
> would repeat the first element 3 times .
>
> I have to either convert `t` to boolean:
>
> a[t==1]
>
> Or use `which`
>
> a[which(t==1)]
>
> How can I "spot" this error?
>
> It often happens in long scripts.
>
> Do I have to check the type each time?
>
> Do you have any suggestions?
>
> __
> 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] How to spot/stop making the same mistake

2021-06-23 Thread Jeff Newmiller
I practically never construct vectors like your `t` so it isn't a problem. And 
since I make a habit of verifying the types of all vectors I am using in 
expressions, if it did come up I would notice.

On June 23, 2021 8:06:05 AM PDT, Phillips Rogfield  
wrote:
>I make the same mistake all over again.
>
>In particular, suppose we have:
>
>a = c(1,2,3,4,5)
>
>and a variable that equals 1 for the elements I want to select:
>
>t = c(1,1,1,0,0)
>
>To select the first 3 elements.
>
>The problem is that
>
>a[t]
>
>would repeat the first element 3 times .
>
>I have to either convert `t` to boolean:
>
>a[t==1]
>
>Or use `which`
>
>a[which(t==1)]
>
>How can I "spot" this error?
>
>It often happens in long scripts.
>
>Do I have to check the type each time?
>
>Do you have any suggestions?
>
>__
>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.


[R] How to spot/stop making the same mistake

2021-06-23 Thread Phillips Rogfield

I make the same mistake all over again.

In particular, suppose we have:

a = c(1,2,3,4,5)

and a variable that equals 1 for the elements I want to select:

t = c(1,1,1,0,0)

To select the first 3 elements.

The problem is that

a[t]

would repeat the first element 3 times .

I have to either convert `t` to boolean:

a[t==1]

Or use `which`

a[which(t==1)]

How can I "spot" this error?

It often happens in long scripts.

Do I have to check the type each time?

Do you have any suggestions?

__
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] Mediation analysis takes up all RAM, then all swap, and then RStudio/terminal suddenly closes

2021-06-23 Thread Phillips Rogfield
Hello Bert,

thank you for your kinds answer.

No I didn't contact the maintainer of the package first, that's my fault :)

I have come to the conclusion that the problem is that I don't have 
enough resources on my PC (RAM) for the task at hand.

I have tried to run it on a remote VM with more RAM and seems to work.

Best regards

On 22/06/2021 17:50, Bert Gunter wrote:
> Please read and follow the posting guide, linked below, which says:
>
> "For questions about functions in standard packages distributed with R 
> (see the FAQ Add-on packages in R 
> ), 
> ask questions on R-help.
> If the question relates to a /contributed package/ , e.g., one 
> downloaded from CRAN, try contacting the package maintainer first. You 
> can also use |find("functionname")| and 
> |packageDescription("packagename")| to find this information. *Only* 
> send such questions to R-help or R-devel if you get no reply or need 
> further assistance. This applies to both requests for help and to bug 
> reports."
>
> So, while you *may* get a useful response here, you should contact the 
> maintainer. If you have already done so, please say so.
>
> Another possibility that may be helpful is the Fedora SIG, 
> https://stat.ethz.ch/mailman/listinfo/r-sig-fedora 
>  , though of 
> course I have no idea whether your problem is OS specific.
>
> 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 Tue, Jun 22, 2021 at 8:38 AM Philips Roger  > wrote:
>
> I am using the mediation
>  >
> package to run a mediation analysis.
>
> But when I call the `mediate` function, R eats up all RAM, then it
> eats
> up all swap, and then RStudio suddenly closes.
>
> The same happens if I call `Rscript` from the terminal, and the
> terminal
> suddenly closes.
>
> Here is measures for RAM and swap. Notice the peaks:
>
> RAM diagnostics
>
> I have Fedora Worstation 24.
>
> This happens BOTH with the R 4.0.5 that uses Open BLAS provided in
> the
> Fedora repository, and a custom R 4.1.0 I compiled from source linked
> against Intel MKL.
>
> It doesn't seem to happen every time, some times (rarely), the RAM
> stays
> constant (around 40/50%) and it works (it takes a long time through).
>
> What is the cause of this? How can I debug?
>
> __
> 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] Wayland backend for R

2021-06-23 Thread Phillips Rogfield

Hello Paul,

thank you for your kind advice.

RStudio doesn't start at all this way. It gives me the following error:

$ QT_QPA_PLATFORM=wayland rstudio
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use 
QT_QPA_PLATFORM=wayland to run on Wayland anyway.

QSocketNotifier: Can only be used with threads started with QThread
Failed to load client buffer integration: wayland-egl

WebEngineContext used before QtWebEngine::initialize() or OpenGL context 
creation failed.

qt.qpa.wayland: No shell integration named "xdg-shell" found
qt.qpa.wayland: No shell integration named "xdg-shell-v6" found
qt.qpa.wayland: No shell integration named "wl-shell" found
qt.qpa.wayland: No shell integration named "ivi-shell" found
qt.qpa.wayland: Loading shell integration failed.
qt.qpa.wayland: Attempted to load the following shells ("xdg-shell", 
"xdg-shell-v6", "wl-shell", "ivi-shell")

qt.qpa.wayland: Wayland does not support QWindow::requestActivate()

Best regards.

On 23/06/2021 02:22, Paul Murrell wrote:

Hi

I do not know of any Wayland backend for R.

You might be able to try the R Studio IDE configured for Wayland and 
see how its graphics device performs ?

https://github.com/rstudio/rstudio/issues/4686

Paul

On 23/06/21 1:25 am, Phillips Rogfield wrote:

I have compiled R from source and I had to install the X11 libraries.

I use Wayland, and I am having problems plotting on X11 (I guess it uses
XWayland) with this version.

Is there a Wayland backend for R?

Some configuration option I need to turn on in order to use it?

__
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] interactively getting alist of functions for a given package?

2021-06-23 Thread Bert Gunter
?ls  and note the "pattern" argument.

e.g.

ls("package:base", pat =".*set.*")

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 Wed, Jun 23, 2021 at 5:38 AM Greg Minshall  wrote:

> hi.
>
> at the R prompt, i often hit, e.g., "data.table::", to try to find
> a routine in a give package.
>
> however, some packages have a *lot* of functions (i'm looking at *you*,
> ggplot2...), so if i know the routine name starts with, e.g., "set", i
> can filter the returned list of routines by typing
> "data.table::set" to get a list of completions.
>
> but, what if i know the name *contains*, but doesn't start with, "set"?
>
> is there an obvious way to find this?  something like the unix-y
> : ls /bin | grep -i "set"
> ?
>
> cheers, Greg
>
> __
> 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] interactively getting alist of functions for a given package?

2021-06-23 Thread Greg Minshall
hi.

at the R prompt, i often hit, e.g., "data.table::", to try to find
a routine in a give package.

however, some packages have a *lot* of functions (i'm looking at *you*,
ggplot2...), so if i know the routine name starts with, e.g., "set", i
can filter the returned list of routines by typing
"data.table::set" to get a list of completions.

but, what if i know the name *contains*, but doesn't start with, "set"?

is there an obvious way to find this?  something like the unix-y
: ls /bin | grep -i "set"
?

cheers, Greg

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