Re: [R] rmarkdown and source call to R file.

2021-01-21 Thread Jeff Newmiller
This is off topic here... please read the Posting Guide about getting help on 
contributed packages.  Check out the RStudio forums.

FWIW you should also look carefully at ?knitr::knit_global ... I don't think it 
does what you seem to think it does.

On January 21, 2021 10:49:17 PM PST, Georgios via R-help  
wrote:
>Hi!
>I'm new in R and this list.
>I made a shiny app using R studio.
>my files are:
>   -server.R
>   -ui.R
>   -helper.R
>   -Report.Rmd.
>
>All the files are on the same directory and helper.R is a file that
>contains a lot of functions used in Report.Rmd and server.R
>
>for some reason I cant call from Report.Rmd the file helper.R
>
>My code in Report.Rmd is
>
>   ## Summarize table
>   ```{r, echo=FALSE}
>   library(knitr)
>   source("helper.R", local = knitr::knit_global())
>   summarized_table<-give_table(params$ldf_summary)
>   kable(summarized_table,"simple")
>   ```
>If I use absolute path it works but since I want to upload it to 
>https://www.shinyapps.io/ I must make it work with relative path.
>
>The message I get is:
>
>   processing file: Report.Rmd
>
>   |.. 
>|  25%
> ordinary text without R code
>
>
>   |   
>|  50%
>   label: unnamed-chunk-1 (with options) 
>   List of 1
>$ echo: logi FALSE
>
>   Quitting from lines 13-17 (Report.Rmd) 
>
>   Warning: Error in file: cannot open the connection
> [No stack trace available]
>
>
>The funny thing is that if I put the cursor inside "" at the beginning
>and I press tab I get the option to choose helper.R. So Im guessing
>that I'm on the right directory.
>Any ideas what I'm missing?
>
>I'm stuck on this lines of code 2 days now.
>I would really appreciate
>any ideas.
>
>
>Thanks in advance for your help!!!
>
>
>ps. I tried all the combinations in Tools->Global Options-> "Evaluate
>chunks in directory" with no luck.
>
>__
>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] rmarkdown and source call to R file.

2021-01-21 Thread Georgios via R-help
Hi!
I'm new in R and this list.
I made a shiny app using R studio.
my files are:
   -server.R
   -ui.R
   -helper.R
   -Report.Rmd.

All the files are on the same directory and helper.R is a file that
contains a lot of functions used in Report.Rmd and server.R

for some reason I cant call from Report.Rmd the file helper.R

My code in Report.Rmd is

   ## Summarize table
   ```{r, echo=FALSE}
   library(knitr)
   source("helper.R", local = knitr::knit_global())
   summarized_table<-give_table(params$ldf_summary)
   kable(summarized_table,"simple")
   ```
If I use absolute path it works but since I want to upload it to 
https://www.shinyapps.io/ I must make it work with relative path.

The message I get is:

   processing file: Report.Rmd

   |.. 
|  25%
 ordinary text without R code


   |   
|  50%
   label: unnamed-chunk-1 (with options) 
   List of 1
$ echo: logi FALSE

   Quitting from lines 13-17 (Report.Rmd) 

   Warning: Error in file: cannot open the connection
 [No stack trace available]


The funny thing is that if I put the cursor inside "" at the beginning
and I press tab I get the option to choose helper.R. So Im guessing
that I'm on the right directory.
Any ideas what I'm missing?

I'm stuck on this lines of code 2 days now.
I would really appreciate
any ideas.


Thanks in advance for your help!!!


ps. I tried all the combinations in Tools->Global Options-> "Evaluate
chunks in directory" with no luck.

__
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] Why is rm(list=ls()) bad practice?

2021-01-21 Thread Duncan Murdoch

On 21/01/2021 5:20 p.m., J C Nash wrote:

In a separate thread Jeff Newmiller wrote:

rm(list=ls()) is a bad practice... especially when posting examples. It doesn't 
clean out everything and it removes objects created by the user.


This query is to ask

1) Why is it bad practice to clear the workspace when presenting an example?
I'm assuming here that people who will try R-help examples will not run them in 
the
middle of something else, which I agree would be unfortunates. 


I think that's exactly the concern.  I doubt it would have happened in 
this instance, but in other cases, people might copy and paste a 
complete example before reading it.  It's safer to say:  "Run this code 
in a clean workspace:", rather than cleaning it out yourself.


Duncan Murdoch


However, one of the

not very nice aspects of R is that it is VERY easy to have stuff hanging around 
(including
overloaded functions and operators) that get you into trouble, and indeed make 
it harder
to reproduce those important "minimal reproducible examples".  This includes 
the .RData
contents. (For information, I can understand the attraction, but I seem to have 
been
burned much more often than I've benefited from a pre-warmed oven.)

2) Is there a good command that really does leave a blank workspace? For testing
purposes, it would be useful to have an assured blank canvas.


Yes, start R with

  R --vanilla

Duncan Murdoch



This post is definitely not to start an argument, but to try to find ways to 
reduce
the possibilities for unanticipated outcomes in examples.

Cheers, JN

__
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] Why is rm(list=ls()) bad practice?

2021-01-21 Thread Bert Gunter
Do you mean:
rm(list = ls(all = TRUE))
?
... or something else?

Bert Gunter

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


On Thu, Jan 21, 2021 at 2:21 PM J C Nash  wrote:

> In a separate thread Jeff Newmiller wrote:
> > rm(list=ls()) is a bad practice... especially when posting examples. It
> doesn't clean out everything and it removes objects created by the user.
>
> This query is to ask
>
> 1) Why is it bad practice to clear the workspace when presenting an
> example?
> I'm assuming here that people who will try R-help examples will not run
> them in the
> middle of something else, which I agree would be unfortunates. However,
> one of the
> not very nice aspects of R is that it is VERY easy to have stuff hanging
> around (including
> overloaded functions and operators) that get you into trouble, and indeed
> make it harder
> to reproduce those important "minimal reproducible examples".  This
> includes the .RData
> contents. (For information, I can understand the attraction, but I seem to
> have been
> burned much more often than I've benefited from a pre-warmed oven.)
>
> 2) Is there a good command that really does leave a blank workspace? For
> testing
> purposes, it would be useful to have an assured blank canvas.
>
> This post is definitely not to start an argument, but to try to find ways
> to reduce
> the possibilities for unanticipated outcomes in examples.
>
> Cheers, JN
>
> __
> 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] rbind common header to file list

2021-01-21 Thread Miluji Sb
Thank you, that was it.

Best,

Milu

On Wed, Jan 20, 2021 at 1:33 PM Eric Berger  wrote:

> for ( file in filelist )
>
>
>
> On Wed, Jan 20, 2021 at 2:21 PM Miluji Sb  wrote:
>
>> Thank you for your reply and the solution. Yes, I would like the date to
>> be
>> the column header for all the files in the list.
>>
>> This is what tried following your suggestion;
>>
>> filelist = list.files(pattern = ".*.txt")
>> date <- 2101
>>
>> for (file %in% filelist){
>>   datalist <- read.table(file)
>>   write.table(datalist, file= file, col.names= date)
>>   }
>>
>> However, I get the following error
>>
>> Error: unexpected SPECIAL in "for (file %in%"
>>
>>
>> Is it something silly I am missing? Thank you again!
>>
>> Best,
>>
>> Milu
>>
>> On Wed, Jan 20, 2021 at 1:29 AM  wrote:
>>
>> > I'd use a for loop. But I may be misunderstanding the q!
>> >
>> >
>> > filelist = list.files(pattern = ".*.txt")
>> > date <- 2101
>> >
>> > for (file %in% filelist) {
>> >
>> > datalist <- read.table(file)
>> >
>> > write.table( datalist, file= file, col.names= date)
>> >
>> > }
>> >
>> > Does what I think you want.
>> > I would actually write to a new filename (sub folder?) To avoid
>> disaster!
>> >
>> >
>> >
>> >
>> >
>> > On 19 Jan 2021 23:45, Miluji Sb  wrote:
>> >
>> > Dear all,
>> >
>> > I have more than 200 text files in a folder without header - example
>> > below.
>> > I would like to read, add a common date header to all the files, and
>> write
>> > (replace) the files.
>> >
>> > ## Read files
>> > filelist = list.files(pattern = ".*.txt")
>> > datalist = lapply(filelist, function(x)read.table(x, header=F))
>> >
>> > ## What I want to add
>> > date <- 2101
>> > datalist _new <- lapply(datalist, function(x) rbind(x, date))
>> >
>> > How do I add this date as a common header and replace the files? Any
>> help
>> > will be highly appreciated. Thank you.
>> >
>> > Best,
>> >
>> > Milu
>> >
>> > ## Sample data
>> > xy <- dput(head(x,6))
>> > structure(list(V1 = c("-5.28082885742185,-0.509039307",
>> > "-6.09873046874998,-0.349584961",
>> > "-2.07150878906248,6.264276123", "-1.11102905273435,6.365716553",
>> > "2.37749633789065,14.57106934", "4.9619079589844,18.91350708"
>> > )), row.names = c(NA, 6L), class = "data.frame")
>> >
>> > [[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] Why is rm(list=ls()) bad practice?

2021-01-21 Thread J C Nash
In a separate thread Jeff Newmiller wrote:
> rm(list=ls()) is a bad practice... especially when posting examples. It 
> doesn't clean out everything and it removes objects created by the user.

This query is to ask

1) Why is it bad practice to clear the workspace when presenting an example?
I'm assuming here that people who will try R-help examples will not run them in 
the
middle of something else, which I agree would be unfortunates. However, one of 
the
not very nice aspects of R is that it is VERY easy to have stuff hanging around 
(including
overloaded functions and operators) that get you into trouble, and indeed make 
it harder
to reproduce those important "minimal reproducible examples".  This includes 
the .RData
contents. (For information, I can understand the attraction, but I seem to have 
been
burned much more often than I've benefited from a pre-warmed oven.)

2) Is there a good command that really does leave a blank workspace? For testing
purposes, it would be useful to have an assured blank canvas.

This post is definitely not to start an argument, but to try to find ways to 
reduce
the possibilities for unanticipated outcomes in examples.

Cheers, JN

__
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] Col names in a data frame

2021-01-21 Thread Bernard Comcast
Thanks - I had seen that parameter but did not think the ( would be illegal 
but now I understand why it considers it illegal.

Thanks again

Bernard
Sent from my iPhone so please excuse the spelling!"

> On Jan 21, 2021, at 4:14 PM, Duncan Murdoch  wrote:
> 
> On 21/01/2021 3:58 p.m., Bernard McGarvey wrote:
>> Here is an example piece of code to illustrate an issue:
>> rm(list=ls()) # Clear Workspace
>> #
>> Data1 <- matrix(data=rnorm(9,0,1),nrow=3,ncol=3)
>> Colnames1 <- c("(A)","(B)","(C)")
>> colnames(Data1) <- Colnames1
>> print(Data1)
>> DataFrame1 <- data.frame(Data1)
>> print(DataFrame1)
>> colnames(DataFrame1) <- Colnames1
>> print(DataFrame1)
>> The results I get are:
>>(A)(B)(C)
>> [1,]  0.4739417  1.3138868  0.4262165
>> [2,] -2.1288083  1.0333770  1.1543404
>> [3,] -0.3401786 -0.7023236 -0.2336880
>>X.A.   X.B.   X.C.
>> 1  0.4739417  1.3138868  0.4262165
>> 2 -2.1288083  1.0333770  1.1543404
>> 3 -0.3401786 -0.7023236 -0.2336880
>> (A)(B)(C)
>> 1  0.4739417  1.3138868  0.4262165
>> 2 -2.1288083  1.0333770  1.1543404
>> 3 -0.3401786 -0.7023236 -0.2336880
>> so that when I make the matrix with headings the parentheses are replaced by 
>> periods but I can add them after creating the data frame and the column 
>> headings are correct.
>> Any ideas on why this occurs?
> 
> By default, data.frame() uses names that are legal variable names, so you can 
> do things like Data1$X.A. You can stop this change by saying
> 
> DataFrame1 <- data.frame(Data1, check.names=FALSE)
> 
> 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] Col names in a data frame

2021-01-21 Thread Bernard Comcast
Thanks - I had seen that parameter but did not think the ( would be illegal but 
now I understand why it considers it illegal.

Thanks again

Bernard
Sent from my iPhone so please excuse the spelling!"

> On Jan 21, 2021, at 4:14 PM, Duncan Murdoch  wrote:
> 
> On 21/01/2021 3:58 p.m., Bernard McGarvey wrote:
>> Here is an example piece of code to illustrate an issue:
>> rm(list=ls()) # Clear Workspace
>> #
>> Data1 <- matrix(data=rnorm(9,0,1),nrow=3,ncol=3)
>> Colnames1 <- c("(A)","(B)","(C)")
>> colnames(Data1) <- Colnames1
>> print(Data1)
>> DataFrame1 <- data.frame(Data1)
>> print(DataFrame1)
>> colnames(DataFrame1) <- Colnames1
>> print(DataFrame1)
>> The results I get are:
>> (A)(B)(C)
>> [1,]  0.4739417  1.3138868  0.4262165
>> [2,] -2.1288083  1.0333770  1.1543404
>> [3,] -0.3401786 -0.7023236 -0.2336880
>> X.A.   X.B.   X.C.
>> 1  0.4739417  1.3138868  0.4262165
>> 2 -2.1288083  1.0333770  1.1543404
>> 3 -0.3401786 -0.7023236 -0.2336880
>>  (A)(B)(C)
>> 1  0.4739417  1.3138868  0.4262165
>> 2 -2.1288083  1.0333770  1.1543404
>> 3 -0.3401786 -0.7023236 -0.2336880
>> so that when I make the matrix with headings the parentheses are replaced by 
>> periods but I can add them after creating the data frame and the column 
>> headings are correct.
>> Any ideas on why this occurs?
> 
> By default, data.frame() uses names that are legal variable names, so you can 
> do things like Data1$X.A. You can stop this change by saying
> 
> DataFrame1 <- data.frame(Data1, check.names=FALSE)
> 
> 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] Col names in a data frame

2021-01-21 Thread Jan T. Kim via R-help
it looks to me that the names are cranked through make.names for
data frames case while that doesn't happen for matrices. Peeking
into the `colnames<-` code supports this idea, but that in turn
uses `names<-` which is a primitive and so defies further easy
peeking.

The data.frame function provides the check.names parameter to
switch this on / off, but for other classes this checking doesn't
seem to be provided.

Perhaps the idea behind this discrepancy is to enable the use of
the $ operator to access columns of the data frame, while that's
not possible for matrices anyway. (Personally, I don't find the
results of make.names that useful, though, and I tend to sanitise
them myself when working with data frames with unwieldy column
names).

Best regards, Jan


On Thu, Jan 21, 2021 at 03:58:44PM -0500, Bernard McGarvey wrote:
> Here is an example piece of code to illustrate an issue:
> 
> rm(list=ls()) # Clear Workspace
> #
> Data1 <- matrix(data=rnorm(9,0,1),nrow=3,ncol=3)
> Colnames1 <- c("(A)","(B)","(C)")
> colnames(Data1) <- Colnames1
> print(Data1)
> DataFrame1 <- data.frame(Data1)
> print(DataFrame1)
> colnames(DataFrame1) <- Colnames1
> print(DataFrame1)
> 
> The results I get are:
> 
> (A)(B)(C)
> [1,]  0.4739417  1.3138868  0.4262165
> [2,] -2.1288083  1.0333770  1.1543404
> [3,] -0.3401786 -0.7023236 -0.2336880
> X.A.   X.B.   X.C.
> 1  0.4739417  1.3138868  0.4262165
> 2 -2.1288083  1.0333770  1.1543404
> 3 -0.3401786 -0.7023236 -0.2336880
>  (A)(B)(C)
> 1  0.4739417  1.3138868  0.4262165
> 2 -2.1288083  1.0333770  1.1543404
> 3 -0.3401786 -0.7023236 -0.2336880
> 
> so that when I make the matrix with headings the parentheses are replaced by 
> periods but I can add them after creating the data frame and the column 
> headings are correct. 
> 
> Any ideas on why this occurs?
> 
> Thanks
> 
> 
> Bernard McGarvey
> Director, Fort Myers Beach Lions Foundation, Inc.
> Retired (Lilly Engineering Fellow).
> 
> __
> 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] Col names in a data frame

2021-01-21 Thread Sarah Goslee
Hi,

data.frame() checks names by default to ensure that column names are
legal, but there's an argument to change that.

>From ?data.frame()


check.names: logical.  If ‘TRUE’ then the names of the variables in the
  data frame are checked to ensure that they are syntactically
  valid variable names and are not duplicated.  If necessary
  they are adjusted (by ‘make.names’) so that they are.

Sarah

On Thu, Jan 21, 2021 at 3:59 PM Bernard McGarvey
 wrote:
>
> Here is an example piece of code to illustrate an issue:
>
> rm(list=ls()) # Clear Workspace
> #
> Data1 <- matrix(data=rnorm(9,0,1),nrow=3,ncol=3)
> Colnames1 <- c("(A)","(B)","(C)")
> colnames(Data1) <- Colnames1
> print(Data1)
> DataFrame1 <- data.frame(Data1)
> print(DataFrame1)
> colnames(DataFrame1) <- Colnames1
> print(DataFrame1)
>
> The results I get are:
>
> (A)(B)(C)
> [1,]  0.4739417  1.3138868  0.4262165
> [2,] -2.1288083  1.0333770  1.1543404
> [3,] -0.3401786 -0.7023236 -0.2336880
> X.A.   X.B.   X.C.
> 1  0.4739417  1.3138868  0.4262165
> 2 -2.1288083  1.0333770  1.1543404
> 3 -0.3401786 -0.7023236 -0.2336880
>  (A)(B)(C)
> 1  0.4739417  1.3138868  0.4262165
> 2 -2.1288083  1.0333770  1.1543404
> 3 -0.3401786 -0.7023236 -0.2336880
>
> so that when I make the matrix with headings the parentheses are replaced by 
> periods but I can add them after creating the data frame and the column 
> headings are correct.
>
> Any ideas on why this occurs?
>
> Thanks
>
>
> Bernard McGarvey
> Director, Fort Myers Beach Lions Foundation, Inc.
> Retired (Lilly Engineering Fellow).
>

-- 
Sarah Goslee (she/her)
http://www.numberwright.com

__
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] Col names in a data frame

2021-01-21 Thread Duncan Murdoch

On 21/01/2021 3:58 p.m., Bernard McGarvey wrote:

Here is an example piece of code to illustrate an issue:

rm(list=ls()) # Clear Workspace
#
Data1 <- matrix(data=rnorm(9,0,1),nrow=3,ncol=3)
Colnames1 <- c("(A)","(B)","(C)")
colnames(Data1) <- Colnames1
print(Data1)
DataFrame1 <- data.frame(Data1)
print(DataFrame1)
colnames(DataFrame1) <- Colnames1
print(DataFrame1)

The results I get are:

 (A)(B)(C)
[1,]  0.4739417  1.3138868  0.4262165
[2,] -2.1288083  1.0333770  1.1543404
[3,] -0.3401786 -0.7023236 -0.2336880
 X.A.   X.B.   X.C.
1  0.4739417  1.3138868  0.4262165
2 -2.1288083  1.0333770  1.1543404
3 -0.3401786 -0.7023236 -0.2336880
  (A)(B)(C)
1  0.4739417  1.3138868  0.4262165
2 -2.1288083  1.0333770  1.1543404
3 -0.3401786 -0.7023236 -0.2336880

so that when I make the matrix with headings the parentheses are replaced by 
periods but I can add them after creating the data frame and the column 
headings are correct.

Any ideas on why this occurs?


By default, data.frame() uses names that are legal variable names, so 
you can do things like Data1$X.A. You can stop this change by saying


DataFrame1 <- data.frame(Data1, check.names=FALSE)

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] Col names in a data frame

2021-01-21 Thread Jeff Newmiller
rm(list=ls()) is a bad practice... especially when posting examples. It doesn't 
clean out everything and it removes objects created by the user.

Read ?data.frame, particularly regarding the check.names parameter. The intent 
is to make it easier to use DF$A notation, though DF$`(A)` is usable if you are 
somewhat experienced with R.

On January 21, 2021 12:58:44 PM PST, Bernard McGarvey 
 wrote:
>Here is an example piece of code to illustrate an issue:
>
>rm(list=ls()) # Clear Workspace
>#
>Data1 <- matrix(data=rnorm(9,0,1),nrow=3,ncol=3)
>Colnames1 <- c("(A)","(B)","(C)")
>colnames(Data1) <- Colnames1
>print(Data1)
>DataFrame1 <- data.frame(Data1)
>print(DataFrame1)
>colnames(DataFrame1) <- Colnames1
>print(DataFrame1)
>
>The results I get are:
>
>(A)(B)(C)
>[1,]  0.4739417  1.3138868  0.4262165
>[2,] -2.1288083  1.0333770  1.1543404
>[3,] -0.3401786 -0.7023236 -0.2336880
>X.A.   X.B.   X.C.
>1  0.4739417  1.3138868  0.4262165
>2 -2.1288083  1.0333770  1.1543404
>3 -0.3401786 -0.7023236 -0.2336880
> (A)(B)(C)
>1  0.4739417  1.3138868  0.4262165
>2 -2.1288083  1.0333770  1.1543404
>3 -0.3401786 -0.7023236 -0.2336880
>
>so that when I make the matrix with headings the parentheses are
>replaced by periods but I can add them after creating the data frame
>and the column headings are correct. 
>
>Any ideas on why this occurs?
>
>Thanks
>
>
>Bernard McGarvey
>Director, Fort Myers Beach Lions Foundation, Inc.
>Retired (Lilly Engineering Fellow).
>
>__
>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] Col names in a data frame

2021-01-21 Thread Bernard McGarvey
Here is an example piece of code to illustrate an issue:

rm(list=ls()) # Clear Workspace
#
Data1 <- matrix(data=rnorm(9,0,1),nrow=3,ncol=3)
Colnames1 <- c("(A)","(B)","(C)")
colnames(Data1) <- Colnames1
print(Data1)
DataFrame1 <- data.frame(Data1)
print(DataFrame1)
colnames(DataFrame1) <- Colnames1
print(DataFrame1)

The results I get are:

(A)(B)(C)
[1,]  0.4739417  1.3138868  0.4262165
[2,] -2.1288083  1.0333770  1.1543404
[3,] -0.3401786 -0.7023236 -0.2336880
X.A.   X.B.   X.C.
1  0.4739417  1.3138868  0.4262165
2 -2.1288083  1.0333770  1.1543404
3 -0.3401786 -0.7023236 -0.2336880
 (A)(B)(C)
1  0.4739417  1.3138868  0.4262165
2 -2.1288083  1.0333770  1.1543404
3 -0.3401786 -0.7023236 -0.2336880

so that when I make the matrix with headings the parentheses are replaced by 
periods but I can add them after creating the data frame and the column 
headings are correct. 

Any ideas on why this occurs?

Thanks


Bernard McGarvey
Director, Fort Myers Beach Lions Foundation, Inc.
Retired (Lilly Engineering Fellow).

__
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] New Package: memify

2021-01-21 Thread Bert Gunter
The new package, memify,  provides a simple way to construct and maintain
functions that keep state i.e. remember their argument lists. This can be
useful when one needs to repeatedly invoke the same function with only a
small number of argument changes at each invocation.

The package is tiny -- basically only a single function, memify() -- and
trivial to use. The examples in the help files should suffice to show how
it works, so if you think this functionality might be useful to you, just
download the package and try it out.

I welcome feedback, either positive or negative, as well as any suggestions
for changes or improvements. Please address any of these to me
**personally** and **not** to this list.

Cheers to all and stay well,

Bert Gunter

[[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] [R-pkgs] simplePHENOTYPES v1.3.0

2021-01-21 Thread Bonfim Fernandes, Samuel
Hi All,

I hope this message finds you well.

We have released simplePHENOTYPES v1.3.0.  Our package simulates single and 
multiple (correlated) traits in a wide range of scenarios, including additive, 
dominance, and epistatic (AxA, AxAxA, ...) models.

Some of the new features include:
- The option to specify what markers will be used as QTNs
- Implemented the parameter "ld_max" and “ld_min” for simulating spurious 
pleiotropy
- Implemented the option for simulating more than two-way epistatic interactions
- Included the parameter 'mean', so traits can be simulated with the desired 
mean (intercept) value.

Please check it our here:
https://cran.r-project.org/package=simplePHENOTYPES
Vignettes for the most common scenarios one would want to simulate may be found 
here:
https://cran.r-project.org/web/packages/simplePHENOTYPES/vignettes/simplePHENOTYPES.html

Best regards,
Samuel Fernandes


[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages
__
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 histogram and lognormal fit on the same time

2021-01-21 Thread Rui Barradas

Hello,

A solution based on Marc's first one, maybe easier? (It doesn't rely on 
multiplying the dlnorm values by 400 since it plots the histogram with 
freq = FALSE.)



set.seed(2020)
data <- rlnorm(100, meanlog = 1, sdlog = 1)

library(MASS)

f <- fitdistr(data, "lognormal")
f$estimate

p <- pretty(range(data))
x <- seq(from = min(p), to = max(p), by = 0.1)

hist(data, freq = FALSE)
lines(x, y = dlnorm(x,
meanlog = f$estimate["meanlog"],
sdlog = f$estimate["sdlog"])
)


Hope this helps,

Rui Barradas


Às 13:12 de 21/01/21, Marc Girondot via R-help escreveu:

Two solutions not exactly equivalent ;

data <- rlnorm(100, meanlog = 1, sdlog = 1)
histdata <- hist(data, ylim=c(0, 100))
library(MASS)

f <- fitdistr(data, "lognormal")

f$estimate

lines(x=seq(from=0, to=50, by=0.1),
  � y=dlnorm(x=seq(from=0, to=50, by=0.1), meanlog =
f$estimate["meanlog"], sdlog = f$estimate["sdlog"])*400
)

library(HelpersMG)

m <- modeled.hist(breaks=histdata$breaks, FUN=plnorm,
  � meanlog = f$estimate["meanlog"], sdlog =
f$estimate["sdlog"], sum = 100)

points(m$x, m$y, pch=19, col="red")

Marc Girondot

Le 21/01/2021 � 12:54, Eric Leroy a �crit�:

Hi,

I would like to plot the histogram of data and fit it with a lognormal
distribution.

The ideal, would be to superimpose the fit on the histogram and write
the results of the fit on the figure.

Right now, I was able to plot the histogram and fit the density with a
lognormal, but I can't combine all together.

Here is the code I wrote :

histdata <- hist(dataframe$data)

library(MASS)

fitdistr(histdata$density, "lognormal")

Can you help me ?

Best regards,


__
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] Plot histogram and lognormal fit on the same time

2021-01-21 Thread Bert Gunter
In future, you should try to search before posting. I realize that getting
good search terms can sometimes be tricky, but not in this case: 'plot
density with histogram in R' or similar on rseek.org or just on your usual
search platform brought up several ways to do it.

As a (slightly offtopic) side issue, be careful with this: both histograms
and smooth density estimates are just that: density **estimates** that
depend on both the data and various parameters, e.g. the location of the
bins for histograms and kernel for kernel density estimates. You may
therefore get plots where the two do not appear to "match" when you use the
defaults for each.


Bert Gunter

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


On Thu, Jan 21, 2021 at 3:54 AM Eric Leroy  wrote:

> Hi,
>
> I would like to plot the histogram of data and fit it with a lognormal
> distribution.
>
> The ideal, would be to superimpose the fit on the histogram and write
> the results of the fit on the figure.
>
> Right now, I was able to plot the histogram and fit the density with a
> lognormal, but I can't combine all together.
>
> Here is the code I wrote :
>
> histdata <- hist(dataframe$data)
>
> library(MASS)
>
> fitdistr(histdata$density, "lognormal")
>
> Can you help me ?
>
> Best regards,
>
> --
>
> *Eric Leroy*
>
> /Responsable de la plateforme microscopie électronique/
>
> /Correspondant Sécurité des Systèmes Informatiques de l'ICMPE/
>
> ICMPE - UMR 7182 - CNRS - UPEC
>
> 2/8, rue Henri Dunant
>
> 94320 Thiais
>
> Tél : 01.49.78.12.09
>
> Fax : 01.49.78.12.03
>
> courriel : le...@icmpe.cnrs.fr 
>
> Page Web : : http://www.icmpe.cnrs.fr 
>
> __
> 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] Plot histogram and lognormal fit on the same time

2021-01-21 Thread Marc Girondot via R-help
Two solutions not exactly equivalent ;

data <- rlnorm(100, meanlog = 1, sdlog = 1)
histdata <- hist(data, ylim=c(0, 100))
library(MASS)

f <- fitdistr(data, "lognormal")

f$estimate

lines(x=seq(from=0, to=50, by=0.1),
 � y=dlnorm(x=seq(from=0, to=50, by=0.1), meanlog = 
f$estimate["meanlog"], sdlog = f$estimate["sdlog"])*400
)

library(HelpersMG)

m <- modeled.hist(breaks=histdata$breaks, FUN=plnorm,
 � meanlog = f$estimate["meanlog"], sdlog = 
f$estimate["sdlog"], sum = 100)

points(m$x, m$y, pch=19, col="red")

Marc Girondot

Le 21/01/2021 � 12:54, Eric Leroy a �crit�:
> Hi,
>
> I would like to plot the histogram of data and fit it with a lognormal 
> distribution.
>
> The ideal, would be to superimpose the fit on the histogram and write 
> the results of the fit on the figure.
>
> Right now, I was able to plot the histogram and fit the density with a 
> lognormal, but I can't combine all together.
>
> Here is the code I wrote :
>
> histdata <- hist(dataframe$data)
>
> library(MASS)
>
> fitdistr(histdata$density, "lognormal")
>
> Can you help me ?
>
> Best regards,
>
>
> __
> 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 histogram and lognormal fit on the same time

2021-01-21 Thread Eric Leroy

Hi,

I would like to plot the histogram of data and fit it with a lognormal 
distribution.


The ideal, would be to superimpose the fit on the histogram and write 
the results of the fit on the figure.


Right now, I was able to plot the histogram and fit the density with a 
lognormal, but I can't combine all together.


Here is the code I wrote :

histdata <- hist(dataframe$data)

library(MASS)

fitdistr(histdata$density, "lognormal")

Can you help me ?

Best regards,

--

*Eric Leroy*

/Responsable de la plateforme microscopie électronique/

/Correspondant Sécurité des Systèmes Informatiques de l'ICMPE/

ICMPE - UMR 7182 - CNRS - UPEC

2/8, rue Henri Dunant

94320 Thiais

Tél : 01.49.78.12.09

Fax : 01.49.78.12.03

courriel : le...@icmpe.cnrs.fr 

Page Web : : http://www.icmpe.cnrs.fr 

__
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] [Rd] R 4.0.4 scheduled for February 15

2021-01-21 Thread Peter Dalgaard via R-help
Full schedule is available on https://developer.r-project.org (or 
https://svn.r-project.org/R-dev-web/trunk/index.html for the impatient).

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
r-de...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

___
r-annou...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-announce

__
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] Problem on Converting "day of year" to "year", "month" and "day" has been solved

2021-01-21 Thread Jibrin Alhassan
Dear R users,
> I want to thank you all for your contributions to the problem I posted. It
> has been solved. Find below the code that solved the problem.
>
df1 <- read.table("SWS1998_2002", header = TRUE)
df1$date <- as.Date(paste(df1$year, df1$day),
 format = "%Y %j",
origin = "1998-01-01")
df2 <- df1[c("date", "Dst")]
head(df2)
#To display all the rows
 print(df2
Thanks,
Jibrin Alhassan

[[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] Runs of at least 5 days with certain value in a rasterbrick in R

2021-01-21 Thread PIKAL Petr
Hallo

I do not know anything about rasterbrick but what about splitting it to list 
according to season. If you have dates starting 1.12. and ending 28.2 as one 
season, diff should be 1day for each season. If you manage to correctly split 
your data, you can cycle through list or use lapply to get desired result.

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Adam Dragula
> Sent: Wednesday, January 20, 2021 10:46 PM
> To: R-help@r-project.org
> Subject: [R] Runs of at least 5 days with certain value in a rasterbrick in R
> 
> Dear R users,
> 
> I am  working with a rasterbrick named X, which has got 6300 time layers.
> Those 6300 time layers represent every winter day since 1.1.1950 till 31.12. I
> dropped all 29th of february so that I had 90 time layers for every season.
> Values throughout the whole domain are between 0.5 and 1.5. I successfully
> made a function, which creates a rasterlayer, which contains amount of runs
> of at least 5 days with values greater than 1.0. So for every grid point, I 
> have
> got amount of events I am looking for. The function is following:
> 
> ff<-function(x,na.rm=TRUE){
> y<-x > 1
> n<- ave(y,cumsum(y == 0), FUN = cumsum)
> sum(n >= 5)
> }
> 
> This works very well, however, there is a problem. After layer which
> represents 28.2., 1.12., 2.12. and so on.. follows. It means, that event 
> starting
> 28.2. may be detected if the criterion is satisfied throughout the first four
> days of following december. Of course I dont wanna detect such events as
> those are two distinct seasons. So I tried something like this (to somehow
> divide it into 70 seasons and calculate function ff for them):
> 
> indices<-rep(1:70,each=90)
> XX<-stackApply(X,indices,fun=ff)
> 
> At first sight, this works and no error is written. However, results are
> miscounted and there is too much events detected, for example 20 events
> are detected in the first layer at maximum, which doesnt make any sense
> (20x5=100, there is just 90 days per season). Other fact is, that this works
> perfectly fine, if I dont divide the whole series and use the criterion 
> through
> original brick X without any indices.
> I cant see where the problem is, so every help is deeply appreciated, maybe
> another way could be more efficient.
> 
> Adam Dragula
> 
> 
> 
>  email?utm_medium=email_source=link_campaign=sig-
> email_content=webmail>
> Bez
> virů. www.avast.com
>  email?utm_medium=email_source=link_campaign=sig-
> email_content=webmail>
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
> 
>   [[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.