Re: [R] creating a data.frame from scratch

2019-04-19 Thread Jeff Newmiller

You seem to be trying to learn R ... sideways... or backwards, perhaps.

Have you read An Introduction to R[1], included with every copy of the 
software? In particular, there are sections on data frames [2] (which 
should be read in the context of the discussion on lists, as it 
is presented. There is also the discussion of factors [3] where the idea 
of using integers to keep track of categorical data is discussed. There 
are many other introductory resources as well which would fill you in on 
these kinds of basic concepts if you find the ItR too computerish.


No R programmer I have ever met constructs data frames by typing in the 
kind of R you showed... that is distinctly characteristic of the 
output of the "dput" function, which is completely general and precise in 
an R-language sense and useful in reproducing whatever data you have in 
your R environment in someone elses environment.


So, one of these might be more typical:

dta1 <- data.frame( Fruit = c( "apple", "banana", "pear", "orange", "kiwi" )
  , Color = c( "red", "yellow", "green", "orange", "green" )
  , Shape = c( "round", "oblong", "pear", "round", "round" )
  , Juice = Juice = c( 1, 0, 0.5, 1, 0 )
  )

dta2 <- read.table( text =
"Fruit  Color  Shape  Juice
apple   redround  1.0
banana  yellow oblong 0.0
peargreen  pear   0.5
orange  orange round  1.0
kiwigreen  round  0.0
", header = TRUE )

I would also strongly encourage you to read the Posting Guide mentioned at 
the bottom of every posting on this mailing list. One issue with your 
email is that sending HTML-formatted email to this list often leads to us 
receiving gibberish because this is a text-only mailing list and the 
translation from HTML to plain text is done differently by different mail 
handling software. Please find the setting for your email software that 
causes it to send plain text (Gmail has a button... you just have to look 
for it). Another issue is that there is an expectation on this list that 
you will have made some effort to wade through the documentation and at 
least mention what documentation you looked at so interested people can 
learn from your difficulty and possibly fix problems in the documentation 
for future users.


[1] https://cran.r-project.org/doc/manuals/r-release/R-intro.html
[2] https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Data-frames
[3] https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Factors

On Fri, 19 Apr 2019, Drake Gossi wrote:


Hello everyone,

Is there any way to create a data.frame from scratch? other than, say, this?


structure(list(Fruit = structure(c(1L, 2L, 5L, 4L, 3L), .Label =

c("apple",
"banana", "kiwi", "orange", "pear"), class = "factor"), Color =
structure(c(3L,
4L, 1L, 2L, 1L), .Label = c("green", "orange", "red", "yellow"
), class = "factor"), Shape = structure(c(3L, 1L, 2L, 3L, 3L), .Label =
c("oblong",
"pear", "round"), class = "factor"), Juice = c(1, 0, 0.5, 1,
0)), class = "data.frame", row.names = c("1", "2", "3", "4",
"5"))


which yields

  Fruit  Color  Shape  Juice
1  applered  round  1.0
2 banana yellow oblong   0.0
3   pear  green   pear   0.5
4 orange orange  round   1.0
5   kiwi  green  round   0.0


I get *that* it works. I just don't know *how* it works, and whether or not
there is another, easier way...

For example,


structure(list(Fruit = structure(c(1L, 2L, 5L, 4L, 3L), .Label =

c("apple", "banana", "kiwi", "orange", "pear") ...


What on earth are these numbers? c(1L, 2L, 5L, 4L, 3L)? and why are they
out of order?

And then why put the fruits out of order? c("apple",
"banana", "kiwi", "orange", "pear")? since that's not a descending order?
since, in the final data.frame, it goes apple, banana, *pear*, *orange*,
kiwi?

So many questions!

Drake

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



---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

__
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] creating a data.frame from scratch

2019-04-19 Thread Drake Gossi
Hello everyone,

Is there any way to create a data.frame from scratch? other than, say, this?

> structure(list(Fruit = structure(c(1L, 2L, 5L, 4L, 3L), .Label =
c("apple",
"banana", "kiwi", "orange", "pear"), class = "factor"), Color =
structure(c(3L,
4L, 1L, 2L, 1L), .Label = c("green", "orange", "red", "yellow"
), class = "factor"), Shape = structure(c(3L, 1L, 2L, 3L, 3L), .Label =
c("oblong",
"pear", "round"), class = "factor"), Juice = c(1, 0, 0.5, 1,
0)), class = "data.frame", row.names = c("1", "2", "3", "4",
"5"))


which yields

   Fruit  Color  Shape  Juice
1  applered  round  1.0
2 banana yellow oblong   0.0
3   pear  green   pear   0.5
4 orange orange  round   1.0
5   kiwi  green  round   0.0


I get *that* it works. I just don't know *how* it works, and whether or not
there is another, easier way...

For example,

> structure(list(Fruit = structure(c(1L, 2L, 5L, 4L, 3L), .Label =
c("apple", "banana", "kiwi", "orange", "pear") ...


What on earth are these numbers? c(1L, 2L, 5L, 4L, 3L)? and why are they
out of order?

And then why put the fruits out of order? c("apple",
"banana", "kiwi", "orange", "pear")? since that's not a descending order?
since, in the final data.frame, it goes apple, banana, *pear*, *orange*,
kiwi?

So many questions!

Drake

[[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] Debugging Rmarkdown

2019-04-19 Thread William Dunlap via R-help
You can set the error handler to save the current state of R in a file,
"last.dump.rda" in the current working directory, when an error occurs with
   options(error=expression(dump.frames(to.file=TRUE,
include.GlobalEnv=TRUE)))
In another R session you can look at what it saved with
   load("last.dump.rda")
   debugger(last.dump)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Apr 19, 2019 at 3:05 PM Patrick Connolly 
wrote:

> There are options to set echo and messages but AFAIK, the text appears
> in the resultant file, but if the script fails, there's no file to inspect.
>
> On 20/04/19 9:50 AM, Bert Gunter wrote:
> > This might be offbase, but do you need to set options to cache the
> > results in the original code chunks to reuse in later chunks? (I
> > haven't worked with knitr lately, so this may be nonsense).
> >
> > Cheers,
> > Bert
> >
> > On Fri, Apr 19, 2019 at 2:03 PM Patrick Connolly
> > mailto:p_conno...@slingshot.co.nz>> wrote:
> >
> >
> > On 19/04/19 12:13 AM, Thierry Onkelinx wrote:
> > > Dear Patrick,
> > >
> > > This is not easy to debug without a reprex
> > >
> > > I would check the content of zzz and wide.i in the loop
> > >
> > > str(wide.i)
> > >  zzz <- rbind(zzz, wide.i)
> > > str(zzz)
> > >
> > That's just what I'm trying to achieve but the debugging doesn't work
> > how it does with regular R code.
> >
> > > Note that the Rmd always runs in a clean environment. This might
> > > explain the difference
> > >
> > The data frames xx and yy are defined in earlier code chunks. Maybe I
> > need to define them again.
> >
> >
> > I'll look closer at it after Easter.
> >
> >
> > Thanks for the suggestion.
> >
> > > Best regards,
> > >
> > > ir. Thierry Onkelinx
> > > Statisticus / Statistician
> > >
> > > Vlaamse Overheid / Government of Flanders
> > > INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR
> > NATURE
> > > AND FOREST
> > > Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality
> > Assurance
> > > thierry.onkel...@inbo.be 
> > >
> > > Havenlaan 88 bus 73, 1000 Brussel
> > > www.inbo.be  
> > >
> > >
> >
>  
> ///
> > > To call in the statistician after the experiment is done may be no
> > > more than asking him to perform a post-mortem examination: he
> > may be
> > > able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
> > > The plural of anecdote is not data. ~ Roger Brinner
> > > The combination of some data and an aching desire for an answer
> > does
> > > not ensure that a reasonable answer can be extracted from a
> > given body
> > > of data. ~ John Tukey
> > >
> >
>  
> ///
> > >
> > > 
> > >
> > >
> > > Op do 18 apr. 2019 om 11:53 schreef Patrick Connolly
> > > mailto:p_conno...@slingshot.co.nz>
> >  > >>:
> > >
> > > I have a function that works in ESS, but it fails if I
> > include it in
> > > an .Rmd file that I tried to knit using Rstudio.  I found
> > advice at:
> > >
> >
> https://www.rstudio.com/products/rstudio/release-notes/debugging-with-rstudio/
> > >
> > > It seems to be not referring to markdown files. Somewhere else
> > > suggested calling render() in the console pane.  I tried
> > that.  The
> > > browser() function interrupts correctly, but I can't find
> > out what the
> > > object zzz in the code below looks like.  Nothing prints the
> > way it
> > > would in a "normal" R buffer.
> > >
> > > code outline:  making zzz out of two dataframes xx and yy
> > >
> > > ##
> > > zzz <- NULL
> > > for(i in xx$Sample){
> > > raw.i <- 
> > >
> > > etc. etc.
> > >
> > > zzz <- rbind(zzz, wide.i)
> > > }
> > >browser()
> > >
> > > names(zzz) <- c("Cultivar", "Test", "Change")
> > > That line fails, with a complaint about zzz being NULL.
> > >
> > > It appears as though the rbind doesn't do anything, but I
> > can't see
> > > what wide.i looks like to get an idea what could be the cause.
> > >
> > > Ideas what I should try are welcome.  I have no idea why the
> > code
> > > works in an R environment but not an Rmd one.
> > >
> > >
> > > R-3.5.2,
> > > platform   x86_64-pc-linux-gnu
> > > arch  

Re: [R] Debugging Rmarkdown

2019-04-19 Thread Jeff Newmiller
Chunks are not isolated... they are executed in sequence in the same 
environment, starting with a fresh environment unrelated to whatever is present 
when you invoke render().

On April 19, 2019 3:00:33 PM PDT, Patrick Connolly  
wrote:
>There are options to set echo and messages but AFAIK, the text appears 
>in the resultant file, but if the script fails, there's no file to
>inspect.
>
>On 20/04/19 9:50 AM, Bert Gunter wrote:
>> This might be offbase, but do you need to set options to cache the 
>> results in the original code chunks to reuse in later chunks? (I 
>> haven't worked with knitr lately, so this may be nonsense).
>>
>> Cheers,
>> Bert
>>
>> On Fri, Apr 19, 2019 at 2:03 PM Patrick Connolly 
>> mailto:p_conno...@slingshot.co.nz>>
>wrote:
>>
>>
>> On 19/04/19 12:13 AM, Thierry Onkelinx wrote:
>> > Dear Patrick,
>> >
>> > This is not easy to debug without a reprex
>> >
>> > I would check the content of zzz and wide.i in the loop
>> >
>> > str(wide.i)
>> >  zzz <- rbind(zzz, wide.i)
>> > str(zzz)
>> >
>> That's just what I'm trying to achieve but the debugging doesn't
>work
>> how it does with regular R code.
>>
>> > Note that the Rmd always runs in a clean environment. This
>might
>> > explain the difference
>> >
>> The data frames xx and yy are defined in earlier code chunks.
>Maybe I
>> need to define them again.
>>
>>
>> I'll look closer at it after Easter.
>>
>>
>> Thanks for the suggestion.
>>
>> > Best regards,
>> >
>> > ir. Thierry Onkelinx
>> > Statisticus / Statistician
>> >
>> > Vlaamse Overheid / Government of Flanders
>> > INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR
>> NATURE
>> > AND FOREST
>> > Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality
>> Assurance
>> > thierry.onkel...@inbo.be 
>> >
>> > Havenlaan 88 bus 73, 1000 Brussel
>> > www.inbo.be  
>> >
>> >
>>
>///
>> > To call in the statistician after the experiment is done may be
>no
>> > more than asking him to perform a post-mortem examination: he
>> may be
>> > able to say what the experiment died of. ~ Sir Ronald Aylmer
>Fisher
>> > The plural of anecdote is not data. ~ Roger Brinner
>> > The combination of some data and an aching desire for an answer
>> does
>> > not ensure that a reasonable answer can be extracted from a
>> given body
>> > of data. ~ John Tukey
>> >
>>
>///
>> >
>> > 
>> >
>> >
>> > Op do 18 apr. 2019 om 11:53 schreef Patrick Connolly
>> > mailto:p_conno...@slingshot.co.nz>
>> > >>:
>> >
>> >     I have a function that works in ESS, but it fails if I
>> include it in
>> >     an .Rmd file that I tried to knit using Rstudio.  I found
>> advice at:
>> >
>>
>https://www.rstudio.com/products/rstudio/release-notes/debugging-with-rstudio/
>> >
>> >     It seems to be not referring to markdown files. Somewhere
>else
>> >     suggested calling render() in the console pane.  I tried
>> that.  The
>> >     browser() function interrupts correctly, but I can't find
>> out what the
>> >     object zzz in the code below looks like.  Nothing prints
>the
>> way it
>> >     would in a "normal" R buffer.
>> >
>> >     code outline:  making zzz out of two dataframes xx and yy
>> >
>> >     ##
>> >         zzz <- NULL
>> >         for(i in xx$Sample){
>> >             raw.i <- 
>> >
>> >             etc. etc.
>> >
>> >             zzz <- rbind(zzz, wide.i)
>> >     }
>> >        browser()
>> >
>> >         names(zzz) <- c("Cultivar", "Test", "Change")
>> >     That line fails, with a complaint about zzz being NULL.
>> >
>> >     It appears as though the rbind doesn't do anything, but I
>> can't see
>> >     what wide.i looks like to get an idea what could be the
>cause.
>> >
>> >     Ideas what I should try are welcome.  I have no idea why
>the
>> code
>> >     works in an R environment but not an Rmd one.
>> >
>> >
>> >     R-3.5.2,
>> >     platform       x86_64-pc-linux-gnu
>> >     arch           x86_64
>> >     os             linux-gnu
>> >     system         x86_64, linux-gnu
>> >
>> >     Rstudio Version 1.1.383
>> >
>> >
>> >
>> >     --
>> >
>>
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>> >
>> >        

[R] Difference between cor_auto (qgraph package) and lavCor (lavaan package)

2019-04-19 Thread Enjalbert Line via R-help
Hello,
I would like to know the diffrence between 2 commands : cor_auto (from qgraph 
package) and lavCor (from lavaan package) to compute a polychoric correlation 
matrix in order to do a network analysis.
I have the responses to the SF-36 questionnaire (36 items with ordered 
responses) and I would like to have a polychoric correlation matrix by 
following the Sacha Epskamp's method. But I have a warning if using cor_auto :  
"Correlation matrix is not positive definite. Finding nearest positive definite 
matrix". I can ignore this warning or not ? Because I try to do a polychoric 
matrix in STATA software and I do not have a warning message.
And I don't understand the difference between lavCor command, because When I 
use lavCor, I do not have the warning message either.
//cor.auto1 <- cor_auto(Data_1it)
//cor.lav1<-lavCor(Data_1it, ordered=names(Data_1it))
Thank you in advance for your answer. 
Line


[[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] Debugging Rmarkdown

2019-04-19 Thread Patrick Connolly
There are options to set echo and messages but AFAIK, the text appears 
in the resultant file, but if the script fails, there's no file to inspect.

On 20/04/19 9:50 AM, Bert Gunter wrote:
> This might be offbase, but do you need to set options to cache the 
> results in the original code chunks to reuse in later chunks? (I 
> haven't worked with knitr lately, so this may be nonsense).
>
> Cheers,
> Bert
>
> On Fri, Apr 19, 2019 at 2:03 PM Patrick Connolly 
> mailto:p_conno...@slingshot.co.nz>> wrote:
>
>
> On 19/04/19 12:13 AM, Thierry Onkelinx wrote:
> > Dear Patrick,
> >
> > This is not easy to debug without a reprex
> >
> > I would check the content of zzz and wide.i in the loop
> >
> > str(wide.i)
> >  zzz <- rbind(zzz, wide.i)
> > str(zzz)
> >
> That's just what I'm trying to achieve but the debugging doesn't work
> how it does with regular R code.
>
> > Note that the Rmd always runs in a clean environment. This might
> > explain the difference
> >
> The data frames xx and yy are defined in earlier code chunks. Maybe I
> need to define them again.
>
>
> I'll look closer at it after Easter.
>
>
> Thanks for the suggestion.
>
> > Best regards,
> >
> > ir. Thierry Onkelinx
> > Statisticus / Statistician
> >
> > Vlaamse Overheid / Government of Flanders
> > INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR
> NATURE
> > AND FOREST
> > Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality
> Assurance
> > thierry.onkel...@inbo.be 
> >
> > Havenlaan 88 bus 73, 1000 Brussel
> > www.inbo.be  
> >
> >
> 
> ///
> > To call in the statistician after the experiment is done may be no
> > more than asking him to perform a post-mortem examination: he
> may be
> > able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
> > The plural of anecdote is not data. ~ Roger Brinner
> > The combination of some data and an aching desire for an answer
> does
> > not ensure that a reasonable answer can be extracted from a
> given body
> > of data. ~ John Tukey
> >
> 
> ///
> >
> > 
> >
> >
> > Op do 18 apr. 2019 om 11:53 schreef Patrick Connolly
> > mailto:p_conno...@slingshot.co.nz>
>  >>:
> >
> >     I have a function that works in ESS, but it fails if I
> include it in
> >     an .Rmd file that I tried to knit using Rstudio.  I found
> advice at:
> >
> 
> https://www.rstudio.com/products/rstudio/release-notes/debugging-with-rstudio/
> >
> >     It seems to be not referring to markdown files. Somewhere else
> >     suggested calling render() in the console pane.  I tried
> that.  The
> >     browser() function interrupts correctly, but I can't find
> out what the
> >     object zzz in the code below looks like.  Nothing prints the
> way it
> >     would in a "normal" R buffer.
> >
> >     code outline:  making zzz out of two dataframes xx and yy
> >
> >     ##
> >         zzz <- NULL
> >         for(i in xx$Sample){
> >             raw.i <- 
> >
> >             etc. etc.
> >
> >             zzz <- rbind(zzz, wide.i)
> >     }
> >        browser()
> >
> >         names(zzz) <- c("Cultivar", "Test", "Change")
> >     That line fails, with a complaint about zzz being NULL.
> >
> >     It appears as though the rbind doesn't do anything, but I
> can't see
> >     what wide.i looks like to get an idea what could be the cause.
> >
> >     Ideas what I should try are welcome.  I have no idea why the
> code
> >     works in an R environment but not an Rmd one.
> >
> >
> >     R-3.5.2,
> >     platform       x86_64-pc-linux-gnu
> >     arch           x86_64
> >     os             linux-gnu
> >     system         x86_64, linux-gnu
> >
> >     Rstudio Version 1.1.383
> >
> >
> >
> >     --
> >
>  ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
> >
> >        ___    Patrick Connolly
> >      {~._.~}                   Great minds discuss ideas
> >      _( Y )_                 Average minds discuss events
> >     (:_~*~_:)                  Small minds discuss people
> >      (_)-(_)                              . Eleanor Roosevelt
> >
> >
>  

Re: [R] Debugging Rmarkdown

2019-04-19 Thread Bert Gunter
This might be offbase, but do you need to set options to cache the results
in the original code chunks to reuse in later chunks? (I haven't worked
with knitr lately, so this may be nonsense).

Cheers,
Bert

On Fri, Apr 19, 2019 at 2:03 PM Patrick Connolly 
wrote:

>
> On 19/04/19 12:13 AM, Thierry Onkelinx wrote:
> > Dear Patrick,
> >
> > This is not easy to debug without a reprex
> >
> > I would check the content of zzz and wide.i in the loop
> >
> > str(wide.i)
> >  zzz <- rbind(zzz, wide.i)
> > str(zzz)
> >
> That's just what I'm trying to achieve but the debugging doesn't work
> how it does with regular R code.
>
> > Note that the Rmd always runs in a clean environment. This might
> > explain the difference
> >
> The data frames xx and yy are defined in earlier code chunks. Maybe I
> need to define them again.
>
>
> I'll look closer at it after Easter.
>
>
> Thanks for the suggestion.
>
> > Best regards,
> >
> > ir. Thierry Onkelinx
> > Statisticus / Statistician
> >
> > Vlaamse Overheid / Government of Flanders
> > INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
> > AND FOREST
> > Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> > thierry.onkel...@inbo.be 
> > Havenlaan 88 bus 73, 1000 Brussel
> > www.inbo.be 
> >
> >
> ///
> > To call in the statistician after the experiment is done may be no
> > more than asking him to perform a post-mortem examination: he may be
> > able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
> > The plural of anecdote is not data. ~ Roger Brinner
> > The combination of some data and an aching desire for an answer does
> > not ensure that a reasonable answer can be extracted from a given body
> > of data. ~ John Tukey
> >
> ///
> >
> > 
> >
> >
> > Op do 18 apr. 2019 om 11:53 schreef Patrick Connolly
> > mailto:p_conno...@slingshot.co.nz>>:
> >
> > I have a function that works in ESS, but it fails if I include it in
> > an .Rmd file that I tried to knit using Rstudio.  I found advice at:
> >
> https://www.rstudio.com/products/rstudio/release-notes/debugging-with-rstudio/
> >
> > It seems to be not referring to markdown files.  Somewhere else
> > suggested calling render() in the console pane.  I tried that.  The
> > browser() function interrupts correctly, but I can't find out what
> the
> > object zzz in the code below looks like.  Nothing prints the way it
> > would in a "normal" R buffer.
> >
> > code outline:  making zzz out of two dataframes xx and yy
> >
> > ##
> > zzz <- NULL
> > for(i in xx$Sample){
> > raw.i <- 
> >
> > etc. etc.
> >
> > zzz <- rbind(zzz, wide.i)
> > }
> >browser()
> >
> > names(zzz) <- c("Cultivar", "Test", "Change")
> > That line fails, with a complaint about zzz being NULL.
> >
> > It appears as though the rbind doesn't do anything, but I can't see
> > what wide.i looks like to get an idea what could be the cause.
> >
> > Ideas what I should try are welcome.  I have no idea why the code
> > works in an R environment but not an Rmd one.
> >
> >
> > R-3.5.2,
> > platform   x86_64-pc-linux-gnu
> > arch   x86_64
> > os linux-gnu
> > system x86_64, linux-gnu
> >
> > Rstudio Version 1.1.383
> >
> >
> >
> > --
> >
>  ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
> >
> >___Patrick Connolly
> >  {~._.~}   Great minds discuss ideas
> >  _( Y )_ Average minds discuss events
> > (:_~*~_:)  Small minds discuss people
> >  (_)-(_)  . Eleanor Roosevelt
> >
> >
>  ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
> >
> > __
> > 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, 

Re: [R] Debugging Rmarkdown

2019-04-19 Thread Jeff Newmiller
I just run each chunk in sequence starting from an fresh restart of R by 
copying code to the R console. However you can use knitr::purl to extract all 
of the code into a regular R script to do whatever debugging you are most 
familiar with.

On April 19, 2019 2:03:00 PM PDT, Patrick Connolly  
wrote:
>
>On 19/04/19 12:13 AM, Thierry Onkelinx wrote:
>> Dear Patrick,
>>
>> This is not easy to debug without a reprex
>>
>> I would check the content of zzz and wide.i in the loop
>>
>> str(wide.i)
>>  zzz <- rbind(zzz, wide.i)
>> str(zzz)
>>
>That's just what I'm trying to achieve but the debugging doesn't work 
>how it does with regular R code.
>
>> Note that the Rmd always runs in a clean environment. This might 
>> explain the difference
>>
>The data frames xx and yy are defined in earlier code chunks. Maybe I 
>need to define them again.
>
>
>I'll look closer at it after Easter.
>
>
>Thanks for the suggestion.
>
>> Best regards,
>>
>> ir. Thierry Onkelinx
>> Statisticus / Statistician
>>
>> Vlaamse Overheid / Government of Flanders
>> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR
>NATURE 
>> AND FOREST
>> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
>> thierry.onkel...@inbo.be 
>> Havenlaan 88 bus 73, 1000 Brussel
>> www.inbo.be 
>>
>>
>///
>> To call in the statistician after the experiment is done may be no 
>> more than asking him to perform a post-mortem examination: he may be 
>> able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
>> The plural of anecdote is not data. ~ Roger Brinner
>> The combination of some data and an aching desire for an answer does 
>> not ensure that a reasonable answer can be extracted from a given
>body 
>> of data. ~ John Tukey
>>
>///
>>
>> 
>>
>>
>> Op do 18 apr. 2019 om 11:53 schreef Patrick Connolly 
>> mailto:p_conno...@slingshot.co.nz>>:
>>
>> I have a function that works in ESS, but it fails if I include it
>in
>> an .Rmd file that I tried to knit using Rstudio.  I found advice
>at:
>>
>https://www.rstudio.com/products/rstudio/release-notes/debugging-with-rstudio/
>>
>> It seems to be not referring to markdown files.  Somewhere else
>> suggested calling render() in the console pane.  I tried that. 
>The
>> browser() function interrupts correctly, but I can't find out
>what the
>> object zzz in the code below looks like.  Nothing prints the way
>it
>> would in a "normal" R buffer.
>>
>> code outline:  making zzz out of two dataframes xx and yy
>>
>> ##
>>     zzz <- NULL
>>     for(i in xx$Sample){
>>         raw.i <- 
>>
>>         etc. etc.
>>
>>         zzz <- rbind(zzz, wide.i)
>> }
>>    browser()
>>
>>     names(zzz) <- c("Cultivar", "Test", "Change")
>> That line fails, with a complaint about zzz being NULL.
>>
>> It appears as though the rbind doesn't do anything, but I can't
>see
>> what wide.i looks like to get an idea what could be the cause.
>>
>> Ideas what I should try are welcome.  I have no idea why the code
>> works in an R environment but not an Rmd one.
>>
>>
>> R-3.5.2,
>> platform       x86_64-pc-linux-gnu
>> arch           x86_64
>> os             linux-gnu
>> system         x86_64, linux-gnu
>>
>> Rstudio Version 1.1.383
>>
>>
>>
>> -- 
>>
>~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>>
>>    ___    Patrick Connolly
>>  {~._.~}                   Great minds discuss ideas
>>  _( Y )_                 Average minds discuss events
>> (:_~*~_:)                  Small minds discuss people
>>  (_)-(_)                              . Eleanor Roosevelt
>>
>>
>~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>>
>> __
>> 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

Re: [R] Debugging Rmarkdown

2019-04-19 Thread Patrick Connolly


On 19/04/19 12:13 AM, Thierry Onkelinx wrote:
> Dear Patrick,
>
> This is not easy to debug without a reprex
>
> I would check the content of zzz and wide.i in the loop
>
> str(wide.i)
>  zzz <- rbind(zzz, wide.i)
> str(zzz)
>
That's just what I'm trying to achieve but the debugging doesn't work 
how it does with regular R code.

> Note that the Rmd always runs in a clean environment. This might 
> explain the difference
>
The data frames xx and yy are defined in earlier code chunks. Maybe I 
need to define them again.


I'll look closer at it after Easter.


Thanks for the suggestion.

> Best regards,
>
> ir. Thierry Onkelinx
> Statisticus / Statistician
>
> Vlaamse Overheid / Government of Flanders
> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE 
> AND FOREST
> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> thierry.onkel...@inbo.be 
> Havenlaan 88 bus 73, 1000 Brussel
> www.inbo.be 
>
> ///
> To call in the statistician after the experiment is done may be no 
> more than asking him to perform a post-mortem examination: he may be 
> able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does 
> not ensure that a reasonable answer can be extracted from a given body 
> of data. ~ John Tukey
> ///
>
> 
>
>
> Op do 18 apr. 2019 om 11:53 schreef Patrick Connolly 
> mailto:p_conno...@slingshot.co.nz>>:
>
> I have a function that works in ESS, but it fails if I include it in
> an .Rmd file that I tried to knit using Rstudio.  I found advice at:
> 
> https://www.rstudio.com/products/rstudio/release-notes/debugging-with-rstudio/
>
> It seems to be not referring to markdown files.  Somewhere else
> suggested calling render() in the console pane.  I tried that.  The
> browser() function interrupts correctly, but I can't find out what the
> object zzz in the code below looks like.  Nothing prints the way it
> would in a "normal" R buffer.
>
> code outline:  making zzz out of two dataframes xx and yy
>
> ##
>     zzz <- NULL
>     for(i in xx$Sample){
>         raw.i <- 
>
>         etc. etc.
>
>         zzz <- rbind(zzz, wide.i)
> }
>    browser()
>
>     names(zzz) <- c("Cultivar", "Test", "Change")
> That line fails, with a complaint about zzz being NULL.
>
> It appears as though the rbind doesn't do anything, but I can't see
> what wide.i looks like to get an idea what could be the cause.
>
> Ideas what I should try are welcome.  I have no idea why the code
> works in an R environment but not an Rmd one.
>
>
> R-3.5.2,
> platform       x86_64-pc-linux-gnu
> arch           x86_64
> os             linux-gnu
> system         x86_64, linux-gnu
>
> Rstudio Version 1.1.383
>
>
>
> -- 
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>
>    ___    Patrick Connolly
>  {~._.~}                   Great minds discuss ideas
>  _( Y )_                 Average minds discuss events
> (:_~*~_:)                  Small minds discuss people
>  (_)-(_)                              . Eleanor Roosevelt
>
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>
> __
> 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] Pause script at input from terminal (interactive use)

2019-04-19 Thread Bernard Comcast
I have used the shiny package to create a web page user interface and it works 
well.

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

> On Apr 19, 2019, at 1:12 AM, Luigi Marongiu  wrote:
> 
> I am realizing as well that R is not the best option for an
> interactive session. I changed the script to get the input from a
> config file; it is less elegant because the procedure now requires
> double the files than with CLI input, but at the end of the day is
> more practical when most of the answer remains the same between
> sessions. Thanks.
> 
>> On Thu, Apr 18, 2019 at 8:47 PM Greg Snow <538...@gmail.com> wrote:
>> 
>> I am not an expert on Rscript, but I don't think that an actual
>> terminal is ever used when using Rscript.  And `interactive()` will
>> probably always be false.
>> 
>> So if you want the script to pause for input, you need to have some
>> form of user interface to work with.
>> 
>> One option is to use the tcltk package (this works on all OS's to my
>> knowledge, but not if you are accessing the computer remotely).  This
>> answer on stack overflow shows some code that may help:
>> https://stackoverflow.com/questions/16847621/get-data-out-of-a-tcltk-function/16847918#16847918
>> 
>> 
>>> On Thu, Apr 18, 2019 at 8:11 AM Luigi Marongiu  
>>> wrote:
>>> 
>>> Dear all,
>>> I am trying to write an interactive script where the user type some
>>> input from the terminal. I used readline() but when I launch the file
>>> with Rscript, the function is overwritten directly, there is no
>>> waiting for the user's input. For instance, this example:
>>> 
>>> VAR1 = as.numeric(readline(prompt = "Enter something -> "))
>>> VAR2 = as.numeric(readline(prompt = "Enter something else -> "))
>>> if(is.na(VAR1)) VAR1 = 0
>>> if(is.na(VAR2)) VAR2 = "empty"
>>> cat("Input was: ", VAR1, " - ", VAR2, "\n")
>>> 
>>> is executed till the end without typing anything on terminal :
>>> 
>>> $ Rscript test.R
>>> Enter something ->
>>> Enter something else ->
>>> Input was:  0  -  empty
>>> 
>>> I also tried with ',1' at the end of readline, but the effect is the
>>> same. I should use the interactive() function but I am confused on its
>>> use.
>>> It is possible to launch R scritps in the interactive mode in the
>>> first place? and if yes, how? Or would python or julia be better
>>> choices in this case?
>>> Thank you.
>>> --
>>> Best regards,
>>> Luigi
>>> 
>>> __
>>> 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.
>> 
>> 
>> 
>> --
>> Gregory (Greg) L. Snow Ph.D.
>> 538...@gmail.com
> 
> 
> 
> -- 
> Best regards,
> Luigi
> 
> __
> 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] picewise function in nls....

2019-04-19 Thread Ivan Krylov
On Fri, 19 Apr 2019 10:12:06 +
akshay kulkarni  wrote:

> But what do you mean by "since fx does not depend on any of the
> parameters you optimize in the nls() call."? Can you give an example?

By "parameters you optimize in the nls() call" I mean `a`. `a` does
not seem to be used in the calculation of `fx`. If it were, it would
have to look like:

fx <- function(x1, x2, a) { ... }
nls(y ~ a*(sin(x2) + fx(x1, x2, a)), start = list(a = ...))

so that nls() would be able to check different values of `a`.

-- 
Best regards,
Ivan

__
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] Pause script at input from terminal (interactive use)

2019-04-19 Thread Ivan Krylov
On Thu, 18 Apr 2019 16:10:41 +0200
Luigi Marongiu  wrote:

> It is possible to launch R scritps in the interactive mode in the
> first place? and if yes, how?

One option would be to use littler
 with its -i
(--interactive) option.

-- 
Best regards,
Ivan

__
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] Looping with looping

2019-04-19 Thread ani jaya
Thank you very much, Dr. Snow, your suggestion helps a lot.

Best,
Saat

On Fri, Apr 19, 2019 at 4:14 AM Greg Snow <538...@gmail.com> wrote:

> When the goal of looping is to compute something and save each
> iteration into a vector or list, then it is usually easier to use the
> lapply/sapply/replicate functions and save the result into a single
> list rather than a bunch of global variables.
>
> Here is a quick example that does the same computations as your code,
> but save the results into a list where each element is a vector of
> length 100:
>
> sam<-c(9,7,8,6,6,7,8,6,7,3)
> a <- lapply(2:9, function(k){
>   replicate(100, mean(sample(sam, k, replace=TRUE)))
> })
>
> # optional
> names(a) <- sprintf("a%i", 2:9)
>
> hist(a[["a2"]]
> hist(a$a9)
> w <- "a5"
> hist(a[[w]])
>
>
> Saving everything into a single list (or matrix/array/etc.) makes it
> easier to loop over all of the results later on (and prevents the hard
> to track down bugs from using dynamically named global variables).
> Here is an example based on the results from above:
>
> par(mfrow=c(3,3))
> for(i in seq_along(a)) {
>   hist(a[[i]], xlab='x', main=sprintf("k = %i", (2:9)[i]))
> }
>
>
>
>
>
> On Thu, Apr 18, 2019 at 9:19 AM ani jaya  wrote:
> >
> > Dear R community,
> >
> > I'm trying to create a looping to see the effect of number of samples
> from
> > one dataset.
> > Lets say I have 10 values in a single data frame and I want to see the
> mean
> > of each sampling let say from 2-9 number of sampling. But I want to do
> the
> > repetition let say up to 100 for each number of sampling and put it in a
> > different dataframe, let say a2,a3,a4,... which contain a2[1] is the mean
> > of first repetition and so on. I believe this is possible but I'm newbie
> > here.
> >
> > > version
> >
> > platform   x86_64-w64-mingw32
> > arch   x86_64
> > os mingw32
> > system x86_64, mingw32
> > status
> > major  3
> > minor  5.3
> > year   2019
> > month  03
> > day11
> > svn rev76217
> > language   R
> > version.string R version 3.5.3 (2019-03-11)
> > nickname   Great Truth
> >
> >
> >  The simple code that I have:
> >
> > sam<-c(9,7,8,6,6,7,8,6,7,3)
> > for (k in seq(2,9,1)){
> > a <- numeric(100)
> >   for (i in 1:100){
> >   a[i] <- mean(sample(sam,k,replace=T))
> >
> >   }
> >   }
> >
> > I can do enough with this code but i want to the variable name also
> > move based on k.
> >
> > I have googling enough and meet assign and paste command but not really
> help.
> > Any help would be appreciate.
> >
> >
> >
> > Best,
> >
> > Saat M.
> >
> > [[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.
>
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> 538...@gmail.com
>

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