Re: [R] Connection to Oracle DB failing from R

2020-08-31 Thread William Dunlap via R-help
Which version of java do you have installed?  Oracle's web site says
ojdbc5.jar is for Java 1.5 and ojdbc6.jar is for more recent versions.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Aug 31, 2020 at 3:56 AM Christofer Bogaso
 wrote:
>
> Hi,
>
> I am trying to establish a connection to a Oracle DB from R and used below
> code which is failing every time I try -
>
> > library(RJDBC)
> Loading required package: DBI
> > jdbcDriver =JDBC("oracle.jdbc.OracleDriver",classPath="ojdbc5.jar")
>
>  *** caught segfault ***
> address 0x854961, cause 'memory not mapped'
>
> Traceback:
>  1: .jinit(classPath)
>  2: JDBC("oracle.jdbc.OracleDriver", classPath = "ojdbc5.jar")
>
> Possible actions:
> 1: abort (with core dump, if enabled)
> 2: normal R exit
> 3: exit R without saving workspace
> 4: exit R saving workspace
> Selection:
>
>
> Below is my session info -
>
> > sessionInfo()
> R version 4.0.2 (2020-06-22)
> Platform: x86_64-apple-darwin17.0 (64-bit)
> Running under: macOS Catalina 10.15.6
>
> Matrix products: default
> BLAS:
>  /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
> LAPACK:
> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
>
> locale:
> [1] C/UTF-8/C/C/C/C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> other attached packages:
> [1] RJDBC_0.2-8  DBI_1.1.0rJava_0.9-13
>
> loaded via a namespace (and not attached):
> [1] compiler_4.0.2
>
> I downloaded the JAR file from
> https://www.oracle.com/database/technologies/jdbcdriver-ucp-downloads.html
>
> Can you please help me to understand why it is failing?
>
> [[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] serialize does not work as expected

2020-08-29 Thread William Dunlap via R-help
For some reason l[[2]] is serialized as a 'compact_realseq' and l[3]]
is not.  They both unserialize to the same thing.  On Windows I get:

> lapply(l, function(x)rawToChar(serialize(x, connection=NULL, ascii=TRUE)))
[[1]]
[1] 
"A\n3\n262146\n197888\n6\nCP1252\n238\n2\n1\n262153\n14\ncompact_intseq\n2\n1\n262153\n4\nbase\n2\n13\n1\n13\n254\n14\n3\n3\n1\n1\n254\n"

[[2]]
[1] 
"A\n3\n262146\n197888\n6\nCP1252\n238\n2\n1\n262153\n15\ncompact_realseq\n2\n1\n262153\n4\nbase\n2\n13\n1\n14\n254\n14\n3\n3\n1\n1\n254\n"

[[3]]
[1] "A\n3\n262146\n197888\n6\nCP1252\n14\n3\n1\n2\n3\n"

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Aug 29, 2020 at 8:37 AM Sigbert Klinke
 wrote:
>
> Hi,
>
> if I create a list with
>
> l <- list(1:3, as.numeric(1:3), c(1,2,3))
>
> and applying
>
> lapply(l, 'class')
> lapply(l, 'mode')
> lapply(l, 'storage.mode')
> lapply(l, 'typeof')
> identical(l[[2]], l[[3]])
>
> then I would believe that as,numeric(1:3) and c(1,2,3) are identical
> objects. However,
>
> lapply(l, serialize, connection=NULL)
>
> returns different results for each list element :(
>
> Any ideas, why it is like that?
>
> Best Sigbert
>
> --
> https://hu.berlin/sk
> https://hu.berlin/mmstat3
>
> __
> 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] Passing formula and weights error

2020-08-28 Thread William Dunlap via R-help
Note that neither call to glm in your myglm function really works -
the first one is using the 'weights' object from the global
environment, not the weights argument.  E.g., in the fresh R session,
where I avoid making unneeded assignments and use fixed x and y for
repeatability,

  > n <- 16
  > data <- data.frame(x = log2(1:n), y = 1:n)
  > myglm2 <- function(formula, data, weights)
  {
  glm(formula, data=data, family=gaussian(), weights=weights)
  }
  > myglm2(y~., data=data, weights=1/(1:n))
  Error in model.frame.default(formula = formula, data = data, weights
= weights,  :
invalid type (closure) for variable '(weights)'

The error arises because glm finds stats::weights, a function, not the
argument called weights.  glm(), lm() and their ilk evaluate their
weights and subset arguments in the environment of the formula.  In
this case environment(y~.) is .GlobalEnv, not the function's
environment.  The following function gives one way to deal with this,
by giving formula a new environment that inherits from its original
environment and contains the extra variables.

  > myglm3 <- function(formula, data, weights)
  {
  envir <- list2env(list(weights=weights), parent=environment(formula))
  environment(formula) <- envir
  glm(formula, data=data, family=gaussian(), weights=weights)
  }
  > myglm3(y~., data=data, weights=1/(1:n))

  Call:  glm(formula = formula, family = gaussian(), data = data,
weights = weights)

  Coefficients:
  (Intercept)x
 -0.09553  2.93352

  Degrees of Freedom: 15 Total (i.e. Null);  14 Residual
  Null Deviance:  60.28
  Residual Deviance: 7.72 AIC: 70.42

This is the same result you get with a direct call to
  glm(y~., data=data, weights=1/(1:n))

This is a common problem and I don't know if there is a FAQ on it or a
standard function to deal with it.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Fri, Aug 28, 2020 at 8:33 AM John Smith  wrote:
>
> Dear R-help:
>
> I am writing a function based on glm and would like some variations of
> weights. In the code below, I couldn't understand why the second glm
> function fails and don't know how to fix it:
>
> Error in eval(extras, data, env) : object 'newweights' not found
>  Calls: print ... eval ->  -> model.frame.default -> eval -> eval
>  Execution halted
>
> ### R code
> y <- rnorm(100)
>  x <- rnorm(100)
>  data <- data.frame(cbind(x, y))
>  weights <- rep(1, 100)
>  n <- 100
>  myglm <- function(formula, data, weights){
>  ## this works
>  print(glm(formula, data, family=gaussian(), weights))
>  ## this is not working
>  newweights <- rep(1, n)
>  glm(formula, data, family=gaussian(), weights=newweights)
>  }
>  myglm(y~., data, weights)
>
> [[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] [External] rNOMADS package

2020-08-24 Thread William Dunlap via R-help
Add the arguments type="source" and repos=NULL to your call to
install.packages().  repos=NULL means that this is a local file, not
something to download from a repository.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Aug 24, 2020 at 8:31 AM Richard M. Heiberger  wrote:
>
> incorrect double slash c://
> use single slash c:/
>
> On Mon, Aug 24, 2020 at 11:21 Philip  wrote:
>
> > I am struggling to install a fix for the rNOMADS package which reads
> > National Weather Service data.  I copied the fix (rNOMADS_2.5.0.tar.gz)
> > from an email to a local drive and then tried to install it with the
> > command below.  I also tried installing it without the .tar.gz extension
> > and without the _2.5.0 extension but I get the same error message.  The
> > author, Daniel Bowman, emailed me that the fix should work for R version
> > 4.0 or better.
> >
> >
> >
> > Do I need to untar it?
> >
> >
> >
> >
> > install.packages("C://Documents/Ballooning/WeatherBriefing/rNOMADS_2.5.0.tar.gz")
> >
> >
> >
> > Installing package into ‘C:/Users/Owner/Documents/R/win-library/4.0’
> >
> > (as ‘lib’ is unspecified)
> >
> > Warning in install.packages :
> >
> >   package ‘C://Documents/Ballooning/WeatherBriefing/rNOMADS_2.5.0.tar.gz’
> > is not available (for R version 4.0.2)
> >
> > [[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] & and |

2020-08-19 Thread William Dunlap via R-help
Instead of intersect you could use grepl(pattern1,x) &
grepl(pattern2,x).  Use which() on the result if you must have
integers, but the logicals that grepl() produces are often easier to
use as subscripts.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Aug 19, 2020 at 8:54 AM Ivan Calandra  wrote:
>
> Indeed!
> I was just hoping that there would be a shorter way... intersect() is a
> nice alternative too. Maybe I can make it work with pipes so that I
> don't have to repeat "mydata" but that's another story.
>
> Thank you for the help!
> Ivan
>
> --
> Dr. Ivan Calandra
> TraCEr, laboratory for Traceology and Controlled Experiments
> MONREPOS Archaeological Research Centre and
> Museum for Human Behavioural Evolution
> Schloss Monrepos
> 56567 Neuwied, Germany
> +49 (0) 2631 9772-243
> https://www.researchgate.net/profile/Ivan_Calandra
>
> On 19/08/2020 17:31, Bert Gunter wrote:
> > Well... wouldn't it be:
> >
> > rep("(ConfoMap.*GuineaPigs)|(GuineaPigs.*ConfoMap)", mydata, value=TRUE)
> >
> > 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, Aug 19, 2020 at 8:23 AM Ivan Calandra  > > wrote:
> >
> > Thank you Bert for the pointer.
> >
> > So I guess the solution is:
> > grep("ConfoMap.+GuineaPigs", mydata, value=TRUE)
> >
> > This is not the case here, but what if "GuineaPigs" comes before
> > "ConfoMap"?
> > Of course I could do two "grep()" calls, but if there a better
> > solution?
> >
> > Ivan
> >
> > --
> > Dr. Ivan Calandra
> > TraCEr, laboratory for Traceology and Controlled Experiments
> > MONREPOS Archaeological Research Centre and
> > Museum for Human Behavioural Evolution
> > Schloss Monrepos
> > 56567 Neuwied, Germany
> > +49 (0) 2631 9772-243
> > https://www.researchgate.net/profile/Ivan_Calandra
> >
> > On 19/08/2020 17:07, Bert Gunter wrote:
> > > "&" is not a regex metacharacter.
> > > See ?regexp
> > >
> > > 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, Aug 19, 2020 at 7:53 AM Ivan Calandra  > 
> > > >> wrote:
> > >
> > > Dear useRs,
> > >
> > > I feel really stupid, but I cannot understand why "&"
> > doesn't work
> > > as I
> > > expect, while "|" does.
> > >
> > > I have the following vector:
> > > mydata <- c("SSFA-ConfoMap_GuineaPigs_NMPfilled.csv",
> > > "SSFA-ConfoMap_Lithics_NMPfilled.csv",
> > > "SSFA-ConfoMap_Sheeps_NMPfilled.csv",
> > > "SSFA-Toothfrax_GuineaPigs.xlsx",
> > > "SSFA-Toothfrax_Lithics.xlsx", "SSFA-Toothfrax_Sheeps.xlsx")
> > > and I want to find the values that include both "ConfoMap" and
> > > "GuineaPigs".
> > >
> > > If I do:
> > > grep("ConfoMap", mydata, value=TRUE)
> > > it returns an empty vector, character(0).
> > >
> > > But if I do:
> > > grep("ConfoMap|GuineaPigs", mydata, value=TRUE)
> > > it returns all the elements that include either "ConfoMap" or
> > > "GuineaPigs", as I would expect.
> > >
> > > So what is wrong with my "&" construct? How can I return the
> > elements
> > > that include both parts?
> > >
> > > Thank you for your help!
> > > Ivan
> > >
> > > --
> > > Dr. Ivan Calandra
> > > TraCEr, laboratory for Traceology and Controlled Experiments
> > > MONREPOS Archaeological Research Centre and
> > > Museum for Human Behavioural Evolution
> > > Schloss Monrepos
> > > 56567 Neuwied, Germany
> > > +49 (0) 2631 9772-243
> > > https://www.researchgate.net/profile/Ivan_Calandra
> > >
> > > __
> > > 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
> > 

Re: [R] Dependent Variable in Logistic Regression

2020-08-01 Thread William Dunlap via R-help
I like using a logical response in cases like this, but put its
construction in the formula so it is unambiguous when I look at the
results later.
> d <- data.frame(Covid=c("Pos","Pos","Neg","Pos","Neg","Neg"), Age=41:46)
> glm(family=binomial, data=d, Covid=="Pos"~Age)

Call:  glm(formula = Covid == "Pos" ~ Age, family = binomial, data = d)

Coefficients:
(Intercept)  Age
 52.810   -1.214

Degrees of Freedom: 5 Total (i.e. Null);  4 Residual
Null Deviance:  8.318
Residual Deviance: 4.956AIC: 8.956


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sat, Aug 1, 2020 at 12:21 PM John Fox  wrote:
>
> Dear Paul,
>
> I think that this thread has gotten unnecessarily complicated. The
> answer, as is easily demonstrated, is that a binary response for a
> binomial GLM in glm() may be a factor, a numeric variable, or a logical
> variable, with identical results; for example:
>
> --- snip -
>
>  > set.seed(123)
>
>  > head(x <- rnorm(100))
> [1] -0.56047565 -0.23017749  1.55870831  0.07050839  0.12928774  1.71506499
>
>  > head(y <- rbinom(100, 1, 1/(1 + exp(-x
> [1] 0 1 1 1 1 0
>
>  > head(yf <- as.factor(y))
> [1] 0 1 1 1 1 0
> Levels: 0 1
>
>  > head(yl <- y == 1)
> [1] FALSE  TRUE  TRUE  TRUE  TRUE FALSE
>
>  > glm(y ~ x, family=binomial)
>
> Call:  glm(formula = y ~ x, family = binomial)
>
> Coefficients:
> (Intercept)x
>   0.3995   1.1670
>
> Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
> Null Deviance:  134.6
> Residual Deviance: 114.9AIC: 118.9
>
>  > glm(yf ~ x, family=binomial)
>
> Call:  glm(formula = yf ~ x, family = binomial)
>
> Coefficients:
> (Intercept)x
>   0.3995   1.1670
>
> Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
> Null Deviance:  134.6
> Residual Deviance: 114.9AIC: 118.9
>
>  > glm(yl ~ x, family=binomial)
>
> Call:  glm(formula = yl ~ x, family = binomial)
>
> Coefficients:
> (Intercept)x
>   0.3995   1.1670
>
> Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
> Null Deviance:  134.6
> Residual Deviance: 114.9AIC: 118.9
>
> --- snip -
>
> The original poster claimed to have encountered an error with a 0/1
> numeric response, but didn't show any data or even a command. I suspect
> that the response was a character variable, but of course can't really
> know that.
>
> Best,
>   John
>
> John Fox, Professor Emeritus
> McMaster University
> Hamilton, Ontario, Canada
> web: https://socialsciences.mcmaster.ca/jfox/
>
> On 2020-08-01 2:25 p.m., Paul Bernal wrote:
> > Dear friend,
> >
> > I am aware that I have a binomial dependent variable, which is covid status
> > (1 if covid positive, and 0 otherwise).
> >
> > My question was if R requires to turn a binomial response variable into a
> > factor or not, that's all.
> >
> > Cheers,
> >
> > Paul
> >
> > El sáb., 1 de agosto de 2020 1:22 p. m., Bert Gunter 
> > 
> > escribió:
> >
> >> ... yes, but so does lm() for a categorical **INdependent** variable with
> >> more than 2 numerically labeled levels. n levels  = (n-1) df for a
> >> categorical covariate, but 1 for a continuous one (unless more complex
> >> models are explicitly specified of course). As I said, the OP seems
> >> confused about whether he is referring to the response or covariates. Or
> >> maybe he just made the same typo I did.
> >>
> >> 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 Sat, Aug 1, 2020 at 11:15 AM Patrick (Malone Quantitative) <
> >> mal...@malonequantitative.com> wrote:
> >>
> >>> No, R does not. glm() does in order to do logistic regression.
> >>>
> >>> On Sat, Aug 1, 2020 at 2:11 PM Paul Bernal 
> >>> wrote:
> >>>
>  Hi Bert,
> 
>  Thank you for the kind reply.
> 
>  But what if I don't turn the variable into a factor. Let's say that in
>  excel I just coded the variable as 1s and 0s and just imported the
>  dataset
>  into R and fitted the logistic regression without turning any categorical
>  variable or dummy variable into a factor?
> 
>  Does R requires every dummy variable to be treated as a factor?
> 
>  Best regards,
> 
>  Paul
> 
>  El sáb., 1 de agosto de 2020 12:59 p. m., Bert Gunter <
>  bgunter.4...@gmail.com> escribió:
> 
> > x <- factor(0:1)
> > x <- factor("yes","no")
> >
> > will produce identical results up to labeling.
> >
> >
> > 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 Sat, Aug 1, 2020 at 10:40 AM Paul Bernal 
> > wrote:
> >
> >> Dear friends,
> >>
> >> 

Re: [R] Looping thorugh dataframe

2020-07-22 Thread William Dunlap via R-help
> library(dplyr, warn.conflicts=FALSE)
> d <- data.frame(Company=c("MATH","IFUL","SSI","MATH","MATH","SSI"), 
> Turnover=c(2,3,5,7,9,11))
> d %>% group_by(Company) %>% summarize(Count=n(), MeanTurnover=mean(Turnover), 
> TotalTurnover=sum(Turnover))
`summarise()` ungrouping output (override with `.groups` argument)
# A tibble: 3 x 4
  Company Count MeanTurnover TotalTurnover
  
1 IFUL13 3
2 MATH3618
3 SSI 2816

[The 'override with .groups' comment arose in a recent version of
dplyr.  It is a bit annoying.]

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Jul 22, 2020 at 4:36 PM e-mail ma015k3113 via R-help
 wrote:
>
> Bert, thanks for responding to my email. I do realise that newbie's like my 
> can expect curt answers but not to worry. I am definitely learning 'R' and 
> what I posted are also statements from R. The statements run perfectly well 
> but don't do what I want them to do. My mistake I have posted sample data. 
> Here is the data:
>
> COMPANY_NUMBER  COMPANY_NAMEYEAR_END_DATE   Turnover
> 22705   AA  30/09/10420,000
> 22705   AA  30/09/09406,000
> 113560  BB  30/06/19474,000
> 192761  CC  31/01/19796,000
> 192761  CC  31/01/18909,000
> 192761  CC  31/01/17788,000
> 5625107 DD  30/06/193,254,002
> 5625107 DD  30/06/181,840,436
>
> All_companies$count <-0
> while All_companies$COMPANY_NAME == All_companies$COMPANY_NAME + 1
> + {All_companies$count=All_companies$count+1}
>
> I want to find out many times each company has appeared in the dataframe and 
> the average of the turnover for the years. Like company AA appears twice and 
> average turnover is 413,000.
>
> 'All_companies' is the name of the dataframe.
>
> In the end apologies for not being more clear the first time around and of 
> course many thanks for your help in advance.
>
> Kind regards
>
>
> Ahson
>
> On 21 July 2020 at 18:41 Bert Gunter  wrote:
>
> What language are you programming in? -- it certainly isn't R.
>
> I suggest that you stop what you're doing and go through an R tutorial or two 
> before proceeding. This list cannot serve as a substitute for doing such 
> homework (is this homework, btw? -- that's off topic here) nor can we provide 
> such tutorials.
>
> I'm pretty sure the answer is quite simple, though it's a bit unclear as you 
> did not provide a reprex (see the posting guide linked below for how to post 
> here). However, I see no purpose in my blurting it out when you do not seem 
> aware of even the most basic R constructs -- e.g. see ?while. Of course, 
> others may disagree and provide you what you seek.
>
>
> 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 )
>
> __
> 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 convert column from millisecond epoch time to yyyy-mm-dd GMT

2020-06-23 Thread William Dunlap via R-help
When you give an example it really helps to (a) show the data as the output
of dput() or dump() so one can copy and paste into R and (b) show the
result (the wrong value or error message) that you got.

You example is missing some quotes and has an unneeded call to lapply().

> dump("Data", file=stdout())
Data <-
structure(list(Id = c("INCBR0005072277", "INCBR0005073034",
"INCBR0005073131",
"INCBR0005074186", "INCBR0005074188"), Timestamp = c(157705920,
157705920, 157705920, 157705920, 157705920),
`Data Type` = c("itsm-ticket", "itsm-ticket", "itsm-ticket",
"itsm-ticket", "itsm-ticket"), Visibility = c("U",
"U", "U", "U", "U"),
TYPE_SERVER = c(0L, 1L, 0L, 0L, 0L)), row.names = c(NA, -5L
), class = "data.frame")
> str(as.POSIXct(Data$Timestamp/1000,
origin=as.POSIXct("1970-01-01",tz="UTC"), tz="UTC"))
 POSIXct[1:5], format: "2019-12-23" "2019-12-23" "2019-12-23" "2019-12-23"
"2019-12-23"

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Jun 23, 2020 at 11:24 AM Gregg via R-help 
wrote:

> Hello to all the smart people out there
>
> I have a data.frame labeled itsm_service_type_field. I need to convert the
> Timestamp field which is epoch time in milliseconds to a -mm-dd GMT
> Date.
>
> Data.frame format is below.
>
> I've attempted to use the lapply and as.POSIXct functions to convert the
> time field in the original data.frame to a new data.frame I've labeled
> "itsm_service_type_field_adjusted_time",
> but I've got the order and syntax wrong.
>
> Help would be so much appreciated.
>
> Thanks in advance.
> Gregg
> Arizona
>
> Details - See Below:
>
> itsm_service_type_field <- fread("itsm_service_type_2018-2019_CONUS.csv")
>
> >???itsm_service_type_field_adjusted_time <-
> lapply(itsm_service_type_field[ , Timestamp], as.POSIXct(Timestamp,
> origin="1970-01-01", tz="GMT"))
>
> head(itsm_service_type_field)
> Id  Timestamp Data Type
> Visibility  TYPE_SERVICE
> 1: INCBR0005072277 157705920 itsm-ticket U0
> 2: INCBR0005073034 157705920 itsm-ticket U1
> 3: INCBR0005073131 157705920 itsm-ticket U0
> 4: INCBR0005074186 157705920 itsm-ticket U0
> 5: INCBR0005074188 157705920 itsm-ticket U0
> 6: INCBR0005074546 157705920 itsm-ticket U
> 0__
> 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] Strange behavior when sampling rows of a data frame

2020-06-19 Thread William Dunlap via R-help
It is a bug that has been present in R since at least R-2.14.0 (the oldest
that I have installed on my laptop).

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Jun 19, 2020 at 10:37 AM Rui Barradas  wrote:

> Hello,
>
>
> Thanks, I hadn't thought of that.
>
> But, why? Is it evaluated once before assignment and a second time when
> the assignment occurs?
>
> To trace both sample and `[<-` gives 2 calls to sample.
>
>
> trace(sample)
> trace(`[<-`)
> df[sample(nrow(df), 3),]$treated <- TRUE
> trace: sample(nrow(df), 3)
> trace: `[<-`(`*tmp*`, sample(nrow(df), 3), , value = list(unit = c(7L,
> 6L, 8L), treated = c(TRUE, TRUE, TRUE)))
> trace: sample(nrow(df), 3)
>
>
> Regards,
>
> Rui Barradas
>
>
> Às 17:20 de 19/06/2020, William Dunlap escreveu:
> > The first subscript argument is getting evaluated twice.
> > > trace(sample)
> > > set.seed(2020); df[i<-sample(10,3), ]$Treated <- TRUE
> > trace: sample(10, 3)
> > trace: sample(10, 3)
> > > i
> > [1]  1 10  4
> > > set.seed(2020); sample(10,3)
> > trace: sample(10, 3)
> > [1] 7 6 8
> > > sample(10,3)
> > trace: sample(10, 3)
> > [1]  1 10  4
> >
> > Bill Dunlap
> > TIBCO Software
> > wdunlap tibco.com <http://tibco.com>
> >
> >
> > On Fri, Jun 19, 2020 at 8:46 AM Rui Barradas  > <mailto:ruipbarra...@sapo.pt>> wrote:
> >
> > Hello,
> >
> > I don't have an answer on the reason why this happens but it seems
> > like
> > a bug. Where?
> >
> > In which of  `[<-.data.frame` or `[<-.default`?
> >
> > A solution is to subset and assign the vector:
> >
> >
> > set.seed(2020)
> > df2 <- data.frame(unit = 1:10)
> > df2$treated <- FALSE
> >
> > df2$treated[sample(nrow(df2), 3)] <- TRUE
> > df2
> > #  unit treated
> > #1 1   FALSE
> > #2 2   FALSE
> > #3 3   FALSE
> > #4 4   FALSE
> > #5 5   FALSE
> > #6 6TRUE
> > #7 7TRUE
> > #8 8TRUE
> > #9 9   FALSE
> > #10   10   FALSE
> >
> >
> > Or
> >
> >
> > set.seed(2020)
> > df3 <- data.frame(unit = 1:10)
> > df3$treated <- FALSE
> >
> > df3[sample(nrow(df3), 3), "treated"] <- TRUE
> > df3
> > # result as expected
> >
> >
> > Hope this helps,
> >
> > Rui  Barradas
> >
> >
> >
> > Às 13:49 de 19/06/2020, Sébastien Lahaie escreveu:
> > > I ran into some strange behavior in R when trying to assign a
> > treatment to
> > > rows in a data frame. I'm wondering whether any R experts can
> > explain
> > > what's going on.
> > >
> > > First, let's assign a treatment to 3 out of 10 rows as follows.
> > >
> > >> df <- data.frame(unit = 1:10)
> > >> df$treated <- FALSE
> > >> s <- sample(nrow(df), 3)
> > >> df[s,]$treated <- TRUE
> > >> df
> > > unit treated
> > >
> > > 1 1   FALSE
> > >
> > > 2 2TRUE
> > >
> > > 3 3   FALSE
> > >
> > > 4 4   FALSE
> > >
> > > 5 5TRUE
> > >
> > > 6 6   FALSE
> > >
> > > 7 7TRUE
> > >
> > > 8 8   FALSE
> > >
> > > 9 9   FALSE
> > >
> > > 10   10   FALSE
> > >
> > > This is as expected. Now we'll just skip the intermediate step
> > of saving
> > > the sampled indices, and apply the treatment directly as follows.
> > >
> > >> df <- data.frame(unit = 1:10)
> > >> df$treated <- FALSE
> > >> df[sample(nrow(df), 3),]$treated <- TRUE
> > >> df
> > > unit treated
> > >
> > > 1 6TRUE
> > >
> > > 2 2   FALSE
> > >
> > > 3 3   FALSE
> > >
> > > 4 9TRUE
> > >
> > > 5 5   FALSE
> > >
> > > 6 6   FALSE
> > >
> > > 7 7   FALSE
> > >
> > > 8 5TRUE
> >   

Re: [R] Strange behavior when sampling rows of a data frame

2020-06-19 Thread William Dunlap via R-help
The first subscript argument is getting evaluated twice.
> trace(sample)
> set.seed(2020); df[i<-sample(10,3), ]$Treated <- TRUE
trace: sample(10, 3)
trace: sample(10, 3)
> i
[1]  1 10  4
> set.seed(2020); sample(10,3)
trace: sample(10, 3)
[1] 7 6 8
> sample(10,3)
trace: sample(10, 3)
[1]  1 10  4

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Jun 19, 2020 at 8:46 AM Rui Barradas  wrote:

> Hello,
>
> I don't have an answer on the reason why this happens but it seems like
> a bug. Where?
>
> In which of  `[<-.data.frame` or `[<-.default`?
>
> A solution is to subset and assign the vector:
>
>
> set.seed(2020)
> df2 <- data.frame(unit = 1:10)
> df2$treated <- FALSE
>
> df2$treated[sample(nrow(df2), 3)] <- TRUE
> df2
> #  unit treated
> #1 1   FALSE
> #2 2   FALSE
> #3 3   FALSE
> #4 4   FALSE
> #5 5   FALSE
> #6 6TRUE
> #7 7TRUE
> #8 8TRUE
> #9 9   FALSE
> #10   10   FALSE
>
>
> Or
>
>
> set.seed(2020)
> df3 <- data.frame(unit = 1:10)
> df3$treated <- FALSE
>
> df3[sample(nrow(df3), 3), "treated"] <- TRUE
> df3
> # result as expected
>
>
> Hope this helps,
>
> Rui  Barradas
>
>
>
> Às 13:49 de 19/06/2020, Sébastien Lahaie escreveu:
> > I ran into some strange behavior in R when trying to assign a treatment
> to
> > rows in a data frame. I'm wondering whether any R experts can explain
> > what's going on.
> >
> > First, let's assign a treatment to 3 out of 10 rows as follows.
> >
> >> df <- data.frame(unit = 1:10)
> >> df$treated <- FALSE
> >> s <- sample(nrow(df), 3)
> >> df[s,]$treated <- TRUE
> >> df
> > unit treated
> >
> > 1 1   FALSE
> >
> > 2 2TRUE
> >
> > 3 3   FALSE
> >
> > 4 4   FALSE
> >
> > 5 5TRUE
> >
> > 6 6   FALSE
> >
> > 7 7TRUE
> >
> > 8 8   FALSE
> >
> > 9 9   FALSE
> >
> > 10   10   FALSE
> >
> > This is as expected. Now we'll just skip the intermediate step of saving
> > the sampled indices, and apply the treatment directly as follows.
> >
> >> df <- data.frame(unit = 1:10)
> >> df$treated <- FALSE
> >> df[sample(nrow(df), 3),]$treated <- TRUE
> >> df
> > unit treated
> >
> > 1 6TRUE
> >
> > 2 2   FALSE
> >
> > 3 3   FALSE
> >
> > 4 9TRUE
> >
> > 5 5   FALSE
> >
> > 6 6   FALSE
> >
> > 7 7   FALSE
> >
> > 8 5TRUE
> >
> > 9 9   FALSE
> >
> > 10   10   FALSE
> >
> > Now the data frame still has 10 rows with 3 assigned to the treatment.
> But
> > the units are garbled. Units 1 and 4 have disappeared, for instance, and
> > there are duplicates for 6 and 9, one assigned to treatment and the other
> > to control. Why would this happen?
> >
> > Thanks,
> > Sebastien
> >
> >   [[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.
>
> --
> Este e-mail foi verificado em termos de vírus pelo software antivírus
> Avast.
> https://www.avast.com/antivirus
>
> __
> 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] Error in gee.fit$working.correlation[1, 2] : subscript out of bounds

2020-06-05 Thread William Dunlap via R-help
The usual reason for the 'subscript out of bounds' error is that an array's
subscripts exceed the dimensions of the array.  In this case
gee.fit$working.correlation is a 1 by 1 matrix, so subscripting with [1,2]
will cause the error.

Here is a self-contained example that you can send the package's maintainer.

> maintainer("geesmv")
[1] "Zheng Li "

> dx <- cbind(id=1:18, y=sin(1:18), expand.grid(period=c(1.1,1.2,1.3),
Ijt=c("i","ii","iii"))[c(1:9,1:9),])
> options(error=recover)
> test <- GEE.var.fg(y ~ factor(period) +
factor(Ijt),id="id",family=gaussian, dx,corstr="exchangeable")
Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27
running glm to get initial regression estimate
  (Intercept) factor(period)1.2 factor(period)1.3 factor(Ijt)ii
   0.02712257   -0.06015777   -0.115557840.04243596
   factor(Ijt)iii
   0.04114518
Error in gee.fit$working.correlation[1, 2] : subscript out of bounds

Enter a frame number, or 0 to exit

1: GEE.var.fg(y ~ factor(period) + factor(Ijt), id = "id", family =
gaussian,

Selection: 1
Called from: top level
Browse[1]> str(gee.fit$working.correlation)
 num [1, 1] 1

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Jun 5, 2020 at 12:28 AM Phat Chau 
wrote:

> Hello,
>
> I have a dataframe in R that looks like the following
>
>   cluster id period   u_3 timeID startTrt Ijterror  y
> 1:   1  1  0 -1.26  11   0   1.2015 17.809
> 2:   1  2  0 -1.26  11   0  -1.6577 14.950
> 3:   1  3  0 -1.26  11   0  -3.8639 12.744
> 4:   1  4  0 -1.26  11   0   1.4978 18.105
> 5:   1  5  0 -1.26  11   0  -5.3182 11.289
>
> When I try to run a gee model on it using the geesmv package which adjusts
> the variance covariance matrix for small sample sizes as follows
>
> test <- GEE.var.fg(y ~ factor(period) +
> factor(Ijt),id="id",family=gaussian, dx,corstr="exchangeable")
>
> I get this error message:
>
> Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27
> running glm to get initial regression estimate
> (Intercept) factor(period)1 factor(period)2 factor(period)3
> factor(period)4 factor(period)5factor(Ijt)1
>   17.25   -8.27   -6.47   -9.13
>  -8.17  -11.898.96
> Error in gee.fit$working.correlation[1, 2] : subscript out of bounds
>
> I think the usual culprit for this kind of error message is that the
> variable being referred to (id in this case I assume) is non-existent. That
> is clearly not the case here and I checked to make sure it is it not a typo.
>
> Does anyone know why this is? How would I troubleshoot this?
>
> Thank you,
> Edward
>
>
> [[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] na.omit not omitting rows

2020-06-04 Thread William Dunlap via R-help
Does droplevels() help?

> d <- data.frame(size = factor(c("S","M","M","L","L"),
levels=c("S","M","L")), id=c(101,NA,NA,104,105))
> str(d)
'data.frame':   5 obs. of  2 variables:
 $ size: Factor w/ 3 levels "S","M","L": 1 2 2 3 3
 $ id  : num  101 NA NA 104 105
> str(na.omit(d))
'data.frame':   3 obs. of  2 variables:
 $ size: Factor w/ 3 levels "S","M","L": 1 3 3
 $ id  : num  101 104 105
 - attr(*, "na.action")= 'omit' Named int [1:2] 2 3
  ..- attr(*, "names")= chr [1:2] "2" "3"
> str(droplevels(na.omit(d)))
'data.frame':   3 obs. of  2 variables:
 $ size: Factor w/ 2 levels "S","L": 1 2 2
 $ id  : num  101 104 105
 - attr(*, "na.action")= 'omit' Named int [1:2] 2 3
  ..- attr(*, "names")= chr [1:2] "2" "3"

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Jun 4, 2020 at 12:18 PM Ted Stankowich <
theodore.stankow...@csulb.edu> wrote:

> Hello! I'm trying to create a subset of a dataset and then remove all rows
> with NAs in them. Ultimately, I am running phylogenetic analyses with trees
> that require the tree tiplabels to match exactly with the rows in the
> dataframe. But when I use na.omit to delete the rows with NAs, there is
> still a trace of those omitted rows in the data.frame, which then causes an
> error in the phylogenetic analyses. Is there any way to completely scrub
> those omitted rows from the dataframe? The code is below. As you can see
> from the result of the final str(Protect1) line, there are attributes with
> the omitted features still in the dataframe (356 species names in the
> UphamComplBinomial factor, but only 319 observations). These traces are
> causing errors with the phylo analyses.
>
> > Protect1=as.data.frame(cbind(UphamComplBinomial, DarkEum, NoctCrep,
> Shade))  #Create the dataframe with variables of interest from an attached
> dataset
> > row.names(Protect1)=Protect1$UphamComplBinomial #assign species names as
> rownames
> > Protect1=as.data.frame(na.omit(Protect1)) #drop rows with missing data
> > str(Protect1)
> 'data.frame': 319 obs. of  4 variables:
>  $ UphamComplBinomial: Factor w/ 356 levels
> "Allenopithecus_nigroviridis_CERCOPITHECIDAE_PRIMATES",..: 1 2 3 4 5 8 9 10
> 11 12 ...
>  $ DarkEum   : Factor w/ 2 levels "0","1": 2 1 2 2 2 2 2 2 2 2 ...
>  $ NoctCrep  : Factor w/ 2 levels "0","1": 1 2 1 1 1 1 1 1 1 1 ...
>  $ Shade : Factor w/ 59 levels "0.1","0.2","0.25",..: 10 58 53
> 17 49 52 52 39 39 41 ...
>  - attr(*, "na.action")= 'omit' Named int  6 7 23 36 37 40 42 50 51 60 ...
>   ..- attr(*, "names")= chr  "Alouatta_macconnelli_ATELIDAE_PRIMATES"
> "Alouatta_nigerrima_ATELIDAE_PRIMATES" "Ateles_fusciceps_ATELIDAE_PRIMATES"
> "Callicebus_baptista_PITHECIIDAE_PRIMATES" ...
>
> Dr. Ted Stankowich
> Associate Professor
> Department of Biological Sciences
> California State University Long Beach
> Long Beach, CA 90840
> theodore.stankow...@csulb.edu
> 562-985-4826
> http://www.csulb.edu/mammal-lab/
> @CSULBMammalLab
>
>
>
>
> [[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] Partial matching list elements in R 4.0

2020-05-27 Thread William Dunlap via R-help
all.equal()

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, May 27, 2020 at 1:13 PM John Harrold 
wrote:

> Thankyou Bert and Bill.
>
> I have one last question. Is there a tool that will recursively compare
> two lists to find differences in both their structure and contents?
>
> I'm afraid that in the process of converting code from $ to [[]] formats I
> may inadvertently introduce some errors. And I'd like to QC it in some way.
>
> Thanks
> John
>
> On Tue, May 26, 2020 at 11:33 AM William Dunlap  wrote:
>
>> Another symptom of this problem is:
>>
>> > {x <- list(Abc=list(Pqr="Old Abc$Pqr")); x$Ab$Pqr <- "New Ab$Pqr" ; x}
>> R version 3.6.2 (2019-12-12) | R version 4.0.0 (2020-04-24)
>> List of 2| List of 2
>>  $ Abc:List of 1 |  $ Abc:List of 1
>>   ..$ Pqr: chr "Old Abc$Pqr" |   ..$ Pqr: chr "New Ab$Pqr"
>>  $ Ab :List of 1 |  $ Ab :List of 1
>>   ..$ Pqr: chr "New Ab$Pqr"  |   ..$ Pqr: chr "New Ab$Pqr"
>>
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>>
>> On Tue, May 26, 2020 at 10:45 AM John Harrold 
>> wrote:
>>
>>> Hello,
>>>
>>>
>>> I'm testing some code in R 4.0, and I'm having an issue with the
>>> following"
>>>
>>> # -
>>> rm(list=ls())
>>> graphics.off()
>>> #load("/tmp/post.RData")
>>> var = list();
>>> # If I uncomment this it fixes things:
>>> # var$options = list(mi   = list(),
>>> #misc = list())
>>> #
>>> var$options$misc$abc = "123"
>>> var$options$mi$something= 13
>>> #
>>>
>>> This is a stripped down example but it exhibits the issue I"m having.
>>> Basically when I create the list element var$options$mi the contents of
>>> var$options$misc move over to var$options$mi. And what was in
>>> var$options$misc become NULL:
>>>
>>> So now var$options looks like:
>>>
>>> var$options
>>> $misc
>>> $misc$abc
>>> NULL
>>>
>>> $mi
>>> $mi$abc
>>> [1] "123"
>>> $mi$something
>>> [1] 13
>>>
>>> This worked (still works) in R 3.5.1. I understand partial matching, but
>>> is
>>> this normal lists moving over to elements like this? I can uncomment the
>>> text mentioned in the example and it seems to fix it, but I'm wondering
>>> if
>>> this is a bug or just my poor programming coming back to bite me.
>>>
>>> I've included my sessionInfo() at the bottom.
>>>
>>> Thanks
>>> John
>>> :wq
>>>
>>>
>>> sessionInfo()
>>>
>>> R version 4.0.0 (2020-04-24)
>>>
>>> Platform: x86_64-apple-darwin17.0 (64-bit)
>>>
>>> Running under: macOS Mojave 10.14.5
>>>
>>>
>>> Matrix products: default
>>>
>>> BLAS:
>>> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
>>>
>>> LAPACK:
>>>
>>> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
>>>
>>>
>>> locale:
>>>
>>> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>>>
>>>
>>> attached base packages:
>>>
>>> [1] stats graphics  grDevices utils datasets  methods   base
>>>
>>>
>>> other attached packages:
>>>
>>> [1] gdata_2.18.0  ggplot2_3.3.0 deSolve_1.28
>>>
>>>
>>> loaded via a namespace (and not attached):
>>>
>>>  [1] Rcpp_1.0.4.6 gtools_3.8.2 withr_2.2.0  assertthat_0.2.1
>>>
>>>  [5] dplyr_0.8.5  digest_0.6.25crayon_1.3.4 grid_4.0.0
>>>
>>>  [9] R6_2.4.1 lifecycle_0.2.0  gtable_0.3.0 magrittr_1.5
>>>
>>> [13] scales_1.1.1 pillar_1.4.4 rlang_0.4.6  vctrs_0.3.0
>>>
>>> [17] ellipsis_0.3.1   glue_1.4.1   purrr_0.3.4  munsell_0.5.0
>>>
>>> [21] compiler_4.0.0   pkgconfig_2.0.3  colorspace_1.4-1 tidyselect_1.1.0
>>>
>>> [25] tibble_3.0.1
>>>
>>> [[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.
>>>
>>
>
> --
> John
> :wq
>

[[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] Partial matching list elements in R 4.0

2020-05-26 Thread William Dunlap via R-help
Another symptom of this problem is:

> {x <- list(Abc=list(Pqr="Old Abc$Pqr")); x$Ab$Pqr <- "New Ab$Pqr" ; x}
R version 3.6.2 (2019-12-12) | R version 4.0.0 (2020-04-24)
List of 2| List of 2
 $ Abc:List of 1 |  $ Abc:List of 1
  ..$ Pqr: chr "Old Abc$Pqr" |   ..$ Pqr: chr "New Ab$Pqr"
 $ Ab :List of 1 |  $ Ab :List of 1
  ..$ Pqr: chr "New Ab$Pqr"  |   ..$ Pqr: chr "New Ab$Pqr"

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, May 26, 2020 at 10:45 AM John Harrold 
wrote:

> Hello,
>
>
> I'm testing some code in R 4.0, and I'm having an issue with the following"
>
> # -
> rm(list=ls())
> graphics.off()
> #load("/tmp/post.RData")
> var = list();
> # If I uncomment this it fixes things:
> # var$options = list(mi   = list(),
> #misc = list())
> #
> var$options$misc$abc = "123"
> var$options$mi$something= 13
> #
>
> This is a stripped down example but it exhibits the issue I"m having.
> Basically when I create the list element var$options$mi the contents of
> var$options$misc move over to var$options$mi. And what was in
> var$options$misc become NULL:
>
> So now var$options looks like:
>
> var$options
> $misc
> $misc$abc
> NULL
>
> $mi
> $mi$abc
> [1] "123"
> $mi$something
> [1] 13
>
> This worked (still works) in R 3.5.1. I understand partial matching, but is
> this normal lists moving over to elements like this? I can uncomment the
> text mentioned in the example and it seems to fix it, but I'm wondering if
> this is a bug or just my poor programming coming back to bite me.
>
> I've included my sessionInfo() at the bottom.
>
> Thanks
> John
> :wq
>
>
> sessionInfo()
>
> R version 4.0.0 (2020-04-24)
>
> Platform: x86_64-apple-darwin17.0 (64-bit)
>
> Running under: macOS Mojave 10.14.5
>
>
> Matrix products: default
>
> BLAS:
> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
>
> LAPACK:
> /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
>
>
> locale:
>
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
>
> attached base packages:
>
> [1] stats graphics  grDevices utils datasets  methods   base
>
>
> other attached packages:
>
> [1] gdata_2.18.0  ggplot2_3.3.0 deSolve_1.28
>
>
> loaded via a namespace (and not attached):
>
>  [1] Rcpp_1.0.4.6 gtools_3.8.2 withr_2.2.0  assertthat_0.2.1
>
>  [5] dplyr_0.8.5  digest_0.6.25crayon_1.3.4 grid_4.0.0
>
>  [9] R6_2.4.1 lifecycle_0.2.0  gtable_0.3.0 magrittr_1.5
>
> [13] scales_1.1.1 pillar_1.4.4 rlang_0.4.6  vctrs_0.3.0
>
> [17] ellipsis_0.3.1   glue_1.4.1   purrr_0.3.4  munsell_0.5.0
>
> [21] compiler_4.0.0   pkgconfig_2.0.3  colorspace_1.4-1 tidyselect_1.1.0
>
> [25] tibble_3.0.1
>
> [[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] NA command in a 'for' loop

2020-04-21 Thread William Dunlap via R-help
Read the files with read.csv(filename) or read.table(sep=",", filename) so
the commas don't become part of the R data.frame.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Apr 21, 2020 at 10:17 AM Helen Sawaya 
wrote:

> Thank you for your patience.
>
> This is the output of dput(head(d, 10))
>
> structure(list(V1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L), .Label = "9.9761E+11,", class = "factor"), V2 = structure(c(1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "threat,", class =
> "factor"),
> V3 = structure(c(1L, 28L, 37L, 48L, 55L, 63L, 73L, 88L, 2L,
> 20L), .Label = c("1,", "10,", "100,", "101,", "102,", "104,",
> "107,", "108,", "109,", "110,", "111,", "112,", "113,", "114,",
> "115,", "116,", "117,", "118,", "119,", "12,", "13,", "14,",
> "15,", "16,", "17,", "18,", "19,", "2,", "20,", "21,", "22,",
> "23,", "24,", "27,", "28,", "29,", "3,", "30,", "31,", "32,",
> "33,", "34,", "35,", "36,", "37,", "38,", "39,", "4,", "42,",
> "44,", "46,", "47,", "48,", "49,", "5,", "50,", "52,", "53,",
> "54,", "55,", "57,", "59,", "6,", "60,", "61,", "62,", "63,",
> "64,", "65,", "66,", "68,", "69,", "7,", "71,", "74,", "75,",
> "76,", "78,", "81,", "82,", "83,", "84,", "85,", "86,", "87,",
> "88,", "89,", "9,", "90,", "91,", "92,", "94,", "95,", "96,",
> "97,", "98,"), class = "factor"), V4 = structure(c(1L, 2L,
> 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L), .Label = c("1,", "2,"), class =
> "factor"),
> V5 = structure(c(2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L), .Label =
> c("1,",
> "2,"), class = "factor"), V6 = structure(c(2L, 1L, 2L, 2L,
> 1L, 2L, 2L, 1L, 2L, 2L), .Label = c("1,", "2,"), class = "factor"),
> V7 = structure(c(2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L), .Label =
> c("1,",
> "2,"), class = "factor"), V8 = structure(c(41L, 92L, 63L,
> 36L, 2L, 81L, 12L, 14L, 23L, 33L), .Label = c("abduction,",
> "abortion,", "abuse,", "accident,", "addicted,", "agony,",
> "anger,", "angry,", "anguish,", "assault,", "bankrupt,",
> "bullet,", "burial,", "cancer,", "cemetery,", "coffin,",
> "corpse,", "crash,", "crisis,", "cruel,", "death,", "defeated,",
> "depressed,", "deserted,", "despair,", "destroy,", "disaster,",
> "disloyal,", "distress,", "dreadful,", "drown,", "dull,",
> "dump,", "emaciated,", "failure,", "fatigue,", "fault,",
> "feeble,", "fever,", "filth,", "forlorn,", "germs,", "gloomy,",
> "hardship,", "hell,", "helpless,", "horror,", "hostage,",
> "hostile,", "hurt,", "idiot,", "infest,", "injury,", "irritable,",
> "jail,", "killer,", "lonely,", "malaria,", "messy,", "misery,",
> "mistake,", "morbid,", "murder,", "mutilate,", "pain,", "panic,",
> "poison,", "prison,", "pus,", "rape,", "rat,", "rejected,",
> "sad,", "scum,", "shame,", "sick,", "slap,", "snake,", "spider,",
> "suicide,", "surgery,", "terrible,", "tormented,", "trash,",
> "trauma,", "ugly,", "ulcer,", "unease,", "unhappy,", "useless,",
> "victim,", "wasp,", "weep,", "worm,", "wound,"), class = "factor"),
> V9 = structure(c(24L, 90L, 73L, 10L, 92L, 33L, 84L, 96L,
> 70L, 57L), .Label = c("alley,", "ankle,", "appliance,", "audience,",
> "bandage,", "bathroom,", "bookcase,", "border,", "branch,",
> "cabinet,", "category,", "clean,", "cliff,", "cold,", "consider,",
> "consoled,", "context,", "country,", "crop,", "dentist,",
> "detail,", "dinner,", "doctor,", "dynamic,", "easygoing,",
> "elbow,", "energetic,", "farm,", "faucet,", "flat,", "flowing,",
> "fork,", "freezer,", "glass,", "grass,", "guess,", "humble,",
> "icebox,", "industry,", "invisible,", "jug,", "lighting,",
> "lion,", "listen,", "little,", "machine,", "metal,", "month,",
> "mushroom,", "napkin,", "news,", "noisy,", "north,", "nudge,",
> "number,", "numerous,", "obey,", "odd,", "oval,", "plant,",
> "possible,", "pot,", "public,", "puzzled,", "quarter,", "rational,",
> "ready,", "reflect,", "reliable,", "repentant,", "sand,",
> "school,", "secret,", "series,", "shark,", "shoe,", "shop,",
> "shortened,", "skyline,", "stable,", "storm,", "stove,",
> "table,", "theory,", "tower,", "truck,", "upgrade,", "upright,",
> "utensil,", "vest,", "vision,", "volcano,", "walk,", "watchful,",
> "window,", "winter,"), class = "factor"), V10 = structure(c(1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "NA,", class =
> "factor"),
> V11 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label =
> "NA,", class = "factor"),
> V12 = structure(c(2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L), .Label =
> c("203,",
> "205,"), class = "factor"), V13 = structure(c(1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "1,", class = "factor"),
> V14 = c(4063L, 4914L, 1508L, 1819L, 1228L, 992L, 1898L, 1174L,
> 1294L, 1417L)), row.names = c(NA, 10L), class = "data.frame”)
>
> When I use the following:
>
> all.files <- list.files(".")
> txt.files <- 

Re: [R] A stopifnot() nastiness, even if not a bug

2020-04-13 Thread William Dunlap via R-help
You can avoid the problem in Martin's example by only giving scalars to
stopifnot().  E.g., using stopifnot(all(x>0)) or stopifnot(length(x)==1,
x>0) instead of stopifnot(x>0).  I think having stopifnot call
all(predicate) if length(predicate)!=1 was probably a mistake.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Apr 13, 2020 at 9:28 AM Hervé Pagès  wrote:

>
>
> On 4/13/20 05:30, Martin Maechler wrote:
> >> peter dalgaard
> >>  on Mon, 13 Apr 2020 12:00:38 +0200 writes:
> >
> >  > Inline...
> >  >> On 13 Apr 2020, at 11:15 , Martin Maechler <
> maech...@stat.math.ethz.ch> wrote:
> >  >>
> >  >>> Bert Gunter
> >  >>> on Sun, 12 Apr 2020 16:30:09 -0700 writes:
> >  >>
> >  >>> Don't know if this has come up before, but ...
> >   x <- c(0,0)
> >   length(x)
> >  >>> [1] 2
> >  >>> ## but
> >   stopifnot(length(x))
> >  >>> Error: length(x) is not TRUE
> >  >>> Called from: top level
> >  >>> ## but
> >   stopifnot(length(x) > 0)  ## not an error;  nor is
> >   stopifnot(as.logical(length(x)))
> >  >>> ## Ouch!
> >  >>
> >  >>> Maybe the man page should say something about not assuming
> automatic
> >  >>> coercion to logical, which is the usual expectation. Or fix
> this.
> >  >>
> >  >>> Bert Gunter
> >  >>
> >  >> Well, what about the top most paragraph of the help page is not
> clear here ?
> >  >>
> >  >>> Description:
> >  >>
> >  >>> If any of the expressions (in '...' or 'exprs') are not 'all'
> >  >>> 'TRUE', 'stop' is called, producing an error message indicating
> >  >>> the _first_ expression which was not ('all') true.
> >  >>
> >
> >  > This, however, is somewhat less clear:
> >
> >  > ..., exprs: any number of (typically but not necessarily
> ‘logical’) R
> >  > expressions, which should each evaluate to (a logical vector
> >  > of all) ‘TRUE’.  Use _either_ ‘...’ _or_ ‘exprs’, the latter
> >
> >  > What does it mean, "typically but not necessarily ‘logical’"?
> >
> > That's a good question: The '()' must have been put there a while
> ago.
> > I agree that it's not at all helpful. Strictly, we are really
> > dealing with unevaluated expressions anyway ("promises"), but
> > definitely all of them must evaluate to logical (vector or
> > array..) of all TRUE values.  In the very beginning of
> > stopifnot(), I had thought that it should also work in other
> > cases, e.g.,  forMatrix(TRUE, 4,5)  {from the Matrix package} etc,
> > but several use cases had convinced us / me that stopifnot
> > should be stricter...
> >
> >  > The code actually tests explicitly with is.logical, as far as I
> can tell.
> >
> >  > This creates a discrepancy between if(!...)stop(...) and
> stopifnot(),
> >
> > yes indeed, on purpose now, for a very long time ...
> >
> > There's another discrepancy, more dangerous I think,
> > as shown in the following
> > {Note this discrepancy has been noted for a long time .. also on
> >   this R-devel list} :
> >
> >m <- matrix(1:12, 3,4)
> >i <- (1:4) %% 2 == 1  & (0:3) %% 5 == 0
> >
> >stopifnot(dim(m[,i]) == c(3,1))   # seems fine
> >
> >if(dim(m[,i]) != c(3,1)) stop("wrong dim") # gives an error (but not
> ..)
>
> mmh... that is not good. I was under the impression that we could at
> least expect 'stopifnot(x)' to be equivalent to 'if (!isTRUE(x))
> stop(...)'. I'll have to revisit my use of stopifnot() in many many
> places... again :-/ Or may be just stop using it and use 'if
> (!isTRUE(...))' instead.
>
> H.
>
> >
> >
> > Martin
> >
> >  >> as in
> >  >> f <- function (x) if (!x) stop(paste(deparse(substitute(x)), "is
> not TRUE"))
> >  >> f(0)
> >  > Error in f(0) : 0 is not TRUE
> >  >> f(1)
> >  >> stopifnot(0)
> >  > Error: 0 is not TRUE
> >  >> stopifnot(1)
> >  > Error: 1 is not TRUE
> >
> >  > -pd
> >
> >
> >  >> If useR's expectations alone would guide the behavior of a
> >  >> computer language, the language would have to behave
> >  >> "personalized" and give different results depending on the user,
> >  >> which may be desirable in medicine or psychotherapy but not with
> R.
> >  >>
> >  >> Martin
> >  >>
> >  >> __
> >  >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more,
> see
> >  >>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp=DwIDaQ=eRAMFD45gAfqt84VtBcfhQ=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA=2kAPk_-c9XEQGS0BB1rf03oPxqQtflyqhqi-0BT8bWE=W8I5sRKBBKZgSjXrQC_PQw6XXUApw5h2DI5EUoDdl9w=
> >  >> PLEASE do read the posting guide
> 

Re: [R] how to create a new column with conditions

2020-04-08 Thread William Dunlap via R-help
>I would like to create a new column called PHENO which would satisfy
>these
>conditions:
>
>if CURRELIG=1 and RTNPTHY=1 than PHENO=1
>if PLASER=2 than PHENO=2
>otherwise is -9

I assume that if CURRELIG==1 and RNPTHY==1 and PLASER==2 then PHENO should
be 1.  Or should that case flag a data error?.

In the former case try
a$PHENO <- with(a, {
tmp <- rep(-9, length(CURRELIG)),
tmp[CURRELIG==1 & RTNPTHY==1] <- 1
tmp[PLASER==2] <- 2
tmp})

In the latter case add some calls to stop() or warning() if any of the
"impossible" cases are seen.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Apr 8, 2020 at 1:32 PM Jeff Newmiller 
wrote:

> Now that you have been shown how to do this, post your (non-working) code
> next time. And configure your email program to send plain text so we will
> see what you saw.
>
> a$PHENO <- ifelse( a$CURRELIG==1
>  & a$RTNPTHY==1
>  , 1
>  ,  ifelse( a$PLASER==2
>   , 2
>   , -9 ) )
>
> or
>
> a$PHENO <- with( a
>, ifelse( CURRELIG==1
>& RTNPTHY==1
>, 1
>, ifelse( PLASER==2
>, 2
>, -9 ) ) )
>
>
> On April 8, 2020 1:17:38 PM PDT, Ana Marija 
> wrote:
> >Hi,
> >
> >I have a data frame like this:
> >
> >> head(a)
> >FID LASER2 CURRELIG PLASER RTNPTHY
> >1 fam1000_G1000  11  1   1
> >2 fam1001_G1001  11  1   1
> >3 fam1003_G1003  21  2   2
> >4 fam1005_G1005  11  1   2
> >5 fam1009_G1009  11  1   2
> >6 fam1052_G1052  11  1   2
> >...
> >
> >I would like to create a new column called PHENO which would satisfy
> >these
> >conditions:
> >
> >if CURRELIG=1 and RTNPTHY=1 than PHENO=1
> >if PLASER=2 than PHENO=2
> >otherwise is -9
> >
> >Thanks
> >Ana
> >
> >   [[alternative HTML version deleted]]
> >
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> --
> Sent from my phone. Please excuse my brevity.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] nls problem

2020-04-03 Thread William Dunlap via R-help
If you will be copying the printed coefficients into your function (instead
of just using fitted() or predict()), then use dput(coef(m)) to get them
printed to full precision.

Also, if you regress on pH-7 instead of pH you don't have to worry so much
about the roundoff or cancellation error.  This is akin to what
poly(pH,degree) does.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Apr 2, 2020 at 9:44 PM Troels Ring  wrote:

> Thank you – yes indeed, on suggestion from Rui I noticed that the problem
> was mainly that I took the parameters from “m” instead of coef(m) i.e
>
> abd
>
> -1630.71   457.68   -32.11
>
> Instead of
>
>   a   b   d
>
> -1630.70993   457.67555   -32.11469
>
>
>
> And that alone saves me.
>
> BW
> Troels
>
>
>
> *Fra:* William Dunlap 
> *Sendt:* 2. april 2020 18:50
> *Til:* Troels Ring 
> *Cc:* r-help mailing list 
> *Emne:* Re: [R] nls problem
>
>
>
> Roundoff/cancelation error: compare the following.  The first is
> equivalent to your function, the last to fitted().
>
>
>
> > with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=2)))
> [,1]  [,2]   [,3] [,4]   [,5]   [,6]
> [,7]   [,8]   [,9] [,10]
> [1,] -0.01635965 0.1076024 0.07477337 -0.007166685 -0.1337865 -0.2851877
> -0.4804638 -0.6865135 -0.9870137 -1.398027
> > with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=4)))
>[,1][,2]   [,3]   [,4]   [,5]   [,6]
> [,7]  [,8]  [,9] [,10]
> [1,] -0.2196286 -0.09864071 -0.1345213 -0.2180792 -0.3463237 -0.4991861
> -0.6959856 -0.903394 -1.205598 -1.618608
> > with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=16)))
>[,1][,2]   [,3]   [,4]   [,5]  [,6]
>  [,7]   [,8]  [,9] [,10]
> [1,] -0.2208705 -0.09989926 -0.1357969 -0.2193638 -0.3476174 -0.500488
> -0.697296 -0.9047119 -1.206926 -1.619947
>
>
>
> Note that your model is linear and could be fitted with
>
>lm(data=aedf, Flux ~ pH + I(pH^2))
>
>lm(data=aedf, Flux ~ poly(pH, 2))
> The latter uses a more stable parameterization.
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
>
>
>
> On Thu, Apr 2, 2020 at 4:15 AM Troels Ring  wrote:
>
> Dear friends - I'm on Win10 with R 6.3.1 and have a very simple problem
> with
> nls which apparently gives a decent fit to the parable below, even without
> starting values. But when I then think I know the meaning of the three
> parameters a, b, and d it goes very wrong. I guess I am again overlooking
> something easy but cannot spot it.
>
> BW
> Troels Ring,
>
> Aalborg, Denmark
>
>
>
>
>
> aedf <- structure(list(Flux = c(-0.141256, -0.154709, -0.215247,
> -0.302691,
>
> -0.32287, -0.511211, -0.605381, -0.813901, -1.11659, -1.76906
>
> ), pH = c(7.06273, 7.11182, 7.16182, 7.18818, 7.21455, 7.23818,
>
>   7.26273, 7.28455, 7.31182, 7.34364)), class = "data.frame",
> row.names = c(NA,
>
>
> -10L))
>
> m <- with(aedf,nls(Flux~a + b*pH + d*pH^2))
>
>
>
> with(aedf,plot(pH,Flux))
>
> with(aedf,lines(pH,fitted(m),lty=1,col="red",lwd=3))
>
>
>
> m
>
> # abd
>
> # -1630.70   457.67   -32.11
>
>
>
> fitted(m)
>
> # 1] -0.22087053 -0.09989926 -0.13579690 -0.21936385 -0.34761742
> -0.50048799
>
> # [7] -0.69729602 -0.90471194 -1.20692552 -1.61994657
>
>
>
> FPG <- function(pH) -1630.70 + 457.67*pH -32.11*pH^2
>
>
>
> FPG(aedf$pH)
>
> # [1] -0.016359649  0.107602395  0.074773375 -0.007166685 -0.133786467
>
> # [6] -0.285187665 -0.480463769 -0.686513537 -0.987013685 -1.398026917
>
>
>
> # So why aren't fitted(m) and FPG(aedf$pH) not closer ("equal")?
>
>
>
>
> This email has been scanned by BullGuard antivirus protection.
> For more info visit www.bullguard.com
> <
> http://www.bullguard.com/tracking.aspx?affiliate=bullguard=smt
> p=/>
>
> [[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.
>
>
> This email has been scanned by BullGuard antivirus protection.
> For more info visit www.bullguard.com
> <http://www.bullguard.com/tracking.aspx?affiliate=bullguard=smtp=/>
>

[[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] nls problem

2020-04-02 Thread William Dunlap via R-help
Roundoff/cancelation error: compare the following.  The first is equivalent
to your function, the last to fitted().

> with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=2)))
[,1]  [,2]   [,3] [,4]   [,5]   [,6]
[,7]   [,8]   [,9] [,10]
[1,] -0.01635965 0.1076024 0.07477337 -0.007166685 -0.1337865 -0.2851877
-0.4804638 -0.6865135 -0.9870137 -1.398027
> with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=4)))
   [,1][,2]   [,3]   [,4]   [,5]   [,6]
  [,7]  [,8]  [,9] [,10]
[1,] -0.2196286 -0.09864071 -0.1345213 -0.2180792 -0.3463237 -0.4991861
-0.6959856 -0.903394 -1.205598 -1.618608
> with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=16)))
   [,1][,2]   [,3]   [,4]   [,5]  [,6]
 [,7]   [,8]  [,9] [,10]
[1,] -0.2208705 -0.09989926 -0.1357969 -0.2193638 -0.3476174 -0.500488
-0.697296 -0.9047119 -1.206926 -1.619947

Note that your model is linear and could be fitted with
   lm(data=aedf, Flux ~ pH + I(pH^2))
   lm(data=aedf, Flux ~ poly(pH, 2))
The latter uses a more stable parameterization.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Apr 2, 2020 at 4:15 AM Troels Ring  wrote:

> Dear friends - I'm on Win10 with R 6.3.1 and have a very simple problem
> with
> nls which apparently gives a decent fit to the parable below, even without
> starting values. But when I then think I know the meaning of the three
> parameters a, b, and d it goes very wrong. I guess I am again overlooking
> something easy but cannot spot it.
>
> BW
> Troels Ring,
>
> Aalborg, Denmark
>
>
>
>
>
> aedf <- structure(list(Flux = c(-0.141256, -0.154709, -0.215247,
> -0.302691,
>
> -0.32287, -0.511211, -0.605381, -0.813901, -1.11659, -1.76906
>
> ), pH = c(7.06273, 7.11182, 7.16182, 7.18818, 7.21455, 7.23818,
>
>   7.26273, 7.28455, 7.31182, 7.34364)), class = "data.frame",
> row.names = c(NA,
>
>
> -10L))
>
> m <- with(aedf,nls(Flux~a + b*pH + d*pH^2))
>
>
>
> with(aedf,plot(pH,Flux))
>
> with(aedf,lines(pH,fitted(m),lty=1,col="red",lwd=3))
>
>
>
> m
>
> # abd
>
> # -1630.70   457.67   -32.11
>
>
>
> fitted(m)
>
> # 1] -0.22087053 -0.09989926 -0.13579690 -0.21936385 -0.34761742
> -0.50048799
>
> # [7] -0.69729602 -0.90471194 -1.20692552 -1.61994657
>
>
>
> FPG <- function(pH) -1630.70 + 457.67*pH -32.11*pH^2
>
>
>
> FPG(aedf$pH)
>
> # [1] -0.016359649  0.107602395  0.074773375 -0.007166685 -0.133786467
>
> # [6] -0.285187665 -0.480463769 -0.686513537 -0.987013685 -1.398026917
>
>
>
> # So why aren't fitted(m) and FPG(aedf$pH) not closer ("equal")?
>
>
>
>
> This email has been scanned by BullGuard antivirus protection.
> For more info visit www.bullguard.com
> <
> http://www.bullguard.com/tracking.aspx?affiliate=bullguard=smt
> p=/
> >
>
>
> [[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] cannot coerce class '"expression"' to a data.frame

2020-03-21 Thread William Dunlap via R-help
Try using the I() function in the call to data.frame.  E.g.,

> d <- data.frame(X=1:3, Y=1:3, Substance=I(expression(H[2]*O, H[2] * O[2],
H*S*O[4])))
> with(d, {plot(X,Y,type="n",xlim=c(0,4)); text(X, Y, Substance)})

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sat, Mar 21, 2020 at 1:45 AM Troels Ring  wrote:

> Dear friends - I have some old data of chemical results and want to
> annotate
> the points with chemical formula. If I just do
>
> ID <- c("HCl 7","HCl 5.25","HCl 3.5","HCL 7 no Na","HCl 3.5  No Na",
>
> "HSO4 7 no  Na",
>
> "HNO3 7 No Na")
>
> I can make a data.frame like
>
> DD <- data.frame(x=1:7,ID)
>
>
>
> and plotting works fine.
>
> But if I try to format sulfuric acid and nitric acid like
>
> ID <- c("HCl 7","HCl 5.25","HCl 3.5","HCL 7 no Na","HCl 3.5  No Na",
>
> expression(paste(HSO[4]," 7 no  Na")),
>
> expression(paste(HNO[3]," 7 No Na")))
>
>
>
> DD <- data.frame(x=1:7,ID)
>
> Elicits an error
>
> Error in as.data.frame.default(x[[i]], optional = TRUE) :
>
>   cannot coerce class '"expression"' to a data.frame
>
> and plotting is prohibited - so how is this bypassed?
>
>
>
> I'm on Windows 10,
>
> R version 3.6.1 (2019-07-05)
>
>
>
> All best wishes
>
> Troels Ring, MD
>
> Aalborg, Denmark
>
>
> This email has been scanned by BullGuard antivirus protection.
> For more info visit www.bullguard.com
> <
> http://www.bullguard.com/tracking.aspx?affiliate=bullguard=smt
> p=/
> >
>
>
> [[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] fit for truncated normal distribution

2020-03-14 Thread William Dunlap via R-help
On Linux it says "Program received signal SIGFPE, Arithmetic exception".  I
think the only way to get a SIGFPE (floating point exception) any more (on
machines with IEEE floating point arithmetic) is taking an integer modulo
zero, which do_druncnorm does when length(x) is 0:
   const double cx = x[i % n_x];
Should R catch SIGFPE and turn it into an error condition?

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sat, Mar 14, 2020 at 12:19 PM peter dalgaard  wrote:

> I see it in three different Mac builds, including a quite recent local
> R-devel build.
>
> It boils down to this:
>
> > dtruncnorm(numeric(0), mean=6.7, sd=1.38, a=-Inf, b=9)
> Floating point exception: 8
>
> which looks like a bug in the truncnorm package, where dtruncnorm() is
> unprepared for a zero-length argument.
>
> (The indirect cause is fitdistrplus:::test1fun, which makes calls like the
> above.)
>
> -pd
>
> > On 14 Mar 2020, at 19:42 , Bert Gunter  wrote:
> >
> > Inline.
> >
> > 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 Sat, Mar 14, 2020 at 10:36 AM |Juergen Hedderich <
> j.hedder...@t-online.de>
> > wrote:
> >
> >> Dear R-help list members,
> >>
> >> the R Session aborted without any 'comment'  for the following 'small
> >> example':
> >>
> >> /library(fitdistrplus)
> >> library(truncnorm)
> >>
> >> filter <- c(4.98, 8.60, 6.37, 4.37, 8.03, 7.43, 6.83, 5.64, 5.43, 6.88,
> >> 4.57, 7.50, 5.69, 7.88, 8.98, 6.79, 8.61, 6.70, 5.14, 7.29)
> >>
> >> fit  <- fitdist(filter, "truncnorm", fix.arg=list(a=-Inf, b=9),
> >> start=list(mean=mean(filter), sd=sd(filter)),
> >> optim.method="L-BFGS-B",
> >> lower=c(-0.1, -0.1), upper=c(Inf, Inf))/
> >>
> >> R worked fine in an 'older'  R-version (environment). Can anyone help
> me?
> >>
> >
> > I can't. But without including the specifics of the older and newer
> > software (including OS version, maybe), maybe no one can.
> > See ?sessionInfo
> >
> >
> >
> >>
> >> Many thanks in advance.
> >>
> >> Best regards
> >>
> >> J. Hedderich
> >>
> >>
> >>[[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.
>
> --
> 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-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] file.access returning -1 for a file on remote Windows drive.

2020-02-28 Thread William Dunlap via R-help
If file.access() says the file is unreadable but file() says it can be
opened, why don't you
just open the file and read it?  You can use tryCatch to deal with problems
opening or
reading the file.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Feb 28, 2020 at 2:54 PM Sam Albers 
wrote:

> Thanks Jeff. I am probably not explaining myself very well but my
> question under what circumstances would
>
> summary(file(remote_file, "rb"))$`can read`
>
> be different from:
>
> file.access(remote_file, 4)
>
> If my permissions were different across remote and local should that
> not be reflected in both of these functions?
>
> On Fri, Feb 28, 2020 at 2:37 PM Jeff Newmiller 
> wrote:
> >
> > Dunno. They agree for me. Maybe look closer at all permissions via
> Windows File Manager?
> >
> > On February 28, 2020 2:06:34 PM PST, Sam Albers <
> tonightstheni...@gmail.com> wrote:
> > >Some additional follow-up:
> > >
> > >> summary(file(remote_file, "rb"))$`can read`
> > >[1] "yes"
> > >
> > >> summary(file(local_file, "rb"))$`can read`
> > >[1] "yes"
> > >
> > >compared to:
> > >
> > >> file.access(local_file, 4)
> > >local.R
> > > 0
> > >
> > >> file.access(remote_file, 4)
> > >remote.R
> > >-1
> > >
> > >Can anyone think why file.access and file would be contradicting each
> > >other?
> > >
> > >Sam
> > >
> > >On Fri, Feb 28, 2020 at 10:47 AM Sam Albers
> > > wrote:
> > >>
> > >> Hi there,
> > >>
> > >> Looking for some help in diagnosing or developing a work around to a
> > >> problem I am having on a Windows machine. I am running R 3.6.2.
> > >>
> > >> I have two identical files, one stored locally and the other stored
> > >on
> > >> a network drive.
> > >>
> > >> For access:
> > >>
> > >> > file.access(local_file, 4)
> > >> local.R
> > >>  0
> > >>
> > >> > file.access(remote_file, 4)
> > >> remote.R
> > >> -1
> > >>
> > >> Also for file.info
> > >>
> > >> > file.info(local_file)$mode:
> > >> [1] "666"
> > >>
> > >> > file.info(remote_file)$mode:
> > >> [1] "666"
> > >>
> > >> Ok so I am access issues. Maybe they are ephemeral and I can change
> > >> the permissions:
> > >>
> > >> > Sys.chmod('remote.R', mode = '666')
> > >> > file.access(remote_file, 4)
> > >> remote.R
> > >> -1
> > >>
> > >> Nope. I am thoroughly stumped and maybe can't make it any further
> > >> because of Windows.
> > >>
> > >> Downstream I am trying to use digest::digest to create a hash but
> > >> digest thinks we don't have permission because file.access is
> > >failing.
> > >> Any thoughts on how I can get file.access to return 0 for the
> > >remote.R
> > >> file? Any ideas?
> > >>
> > >> Thanks in advance,
> > >>
> > >> Sam
> > >
> > >__
> > >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.
>

[[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 index the occasions in a vector repeatedly under condition 1? if not, it will give a new index.

2020-02-21 Thread William Dunlap via R-help
> all.equal(y, ave(d, cumsum(c(TRUE,is_true(diff(a)!=0))),
FUN=function(di)1L+cumsum(is_true(di>15
[1] TRUE

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 19, 2020 at 7:20 PM Lijun Zhao 
wrote:

> Dear William,
>
> Thank you so much.
>
>
>
> I am quiet new in R. I would like to do this based on another repeated
> variables.
>
>
>
> For example:
>
> a<-c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2)
>
> d<-c(NA, 0, 0, 0, 8, 0, 577, 69, 0, NA, 0, 0, 0, 8, 0, 577, 69, 0)
>
> the outcome I want is :
>
> y<-c(1, 1, 1, 1, 1, 1, 2, 3, 3, 1, 1, 1 ,1, 1 ,1, 2, 3, 3)
>
>
>
> Therefore, I would like to create y based on the variable a. once variable
> a has changed, the index will start from 1 again. I wrote a for loop, but
> it did not give me what I want. Could you please help me again?
>
>
>
> Thanks in advance,
>
>
>
> Lijun
>
>
>
>
>
>
>
> *From:* William Dunlap 
> *Sent:* Thursday, 20 February 2020 1:53 AM
> *To:* Lijun Zhao 
> *Cc:* r-help@r-project.org
> *Subject:* Re: [R] How to index the occasions in a vector repeatedly
> under condition 1? if not, it will give a new index.
>
>
>
> Use cumsum(logicalVector) to increment a counter at the TRUE positions in
> logicalVector. .  E.g.,
>
>
>
> > d <- c(NA, 0, 0, 0, 8, 0, 577, 69, 0)
>
> > is_true <- function(x) !is.na(x) & x
> > 1 + cumsum( is_true(d >= 15) )
> [1] 1 1 1 1 1 1 2 3 3
>
>
>
> Some packages have the equivalent of that is_true function, which maps
> FALSE and NA to FALSE and TRUE to TRUE.  I don't think core R contains such
> a function.
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
>
>
>
> On Wed, Feb 19, 2020 at 7:08 AM Lijun Zhao 
> wrote:
>
> Dear all,
> Could you please help me how to get the output as I described in the
> following example?
>
> x<-c(543,  543,  543,  543,  551 , 551 ,1128 ,1197, 1197)
> diff<-x-lag(x)
> diff
> [1]  NA   0   0   0   8   0 577  69   0
>
> How to index the occasions in x repeatedly if the diff<15? if diff>=15, it
> will give a new index.
> I want the output be like y.
>
> y<-c(1,1,1,1,1,1,2,3,3)
>
> Thank you so much,
>
> Lijun Zhao (PhD Candidate)
> Nutrition and Metabolism
> Level 7 SAHMRI
> North Terrace
> Adelaide 5005
> Ph: +61 8 8128 4898
> e-mail: lijun.z...@adelaide.edu.au<mailto:lijun.z...@adelaide.edu.au> or
> lijun.z...@sahmri.com<mailto:lijun.z...@sahmri.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.
>
>

[[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 index the occasions in a vector repeatedly under condition 1? if not, it will give a new index.

2020-02-19 Thread William Dunlap via R-help
Use cumsum(logicalVector) to increment a counter at the TRUE positions in
logicalVector. .  E.g.,

> d <- c(NA, 0, 0, 0, 8, 0, 577, 69, 0)
> is_true <- function(x) !is.na(x) & x
> 1 + cumsum( is_true(d >= 15) )
[1] 1 1 1 1 1 1 2 3 3

Some packages have the equivalent of that is_true function, which maps
FALSE and NA to FALSE and TRUE to TRUE.  I don't think core R contains such
a function.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 19, 2020 at 7:08 AM Lijun Zhao 
wrote:

> Dear all,
> Could you please help me how to get the output as I described in the
> following example?
>
> x<-c(543,  543,  543,  543,  551 , 551 ,1128 ,1197, 1197)
> diff<-x-lag(x)
> diff
> [1]  NA   0   0   0   8   0 577  69   0
>
> How to index the occasions in x repeatedly if the diff<15? if diff>=15, it
> will give a new index.
> I want the output be like y.
>
> y<-c(1,1,1,1,1,1,2,3,3)
>
> Thank you so much,
>
> Lijun Zhao (PhD Candidate)
> Nutrition and Metabolism
> Level 7 SAHMRI
> North Terrace
> Adelaide 5005
> Ph: +61 8 8128 4898
> e-mail: lijun.z...@adelaide.edu.au or
> lijun.z...@sahmri.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.
>

[[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] Aggregate individual level data to age categories

2020-02-12 Thread William Dunlap via R-help
You didn't say how you wanted to use it as a data.frame, but here is one way

d <- data.frame(
check.names = FALSE,
age = c(45L, 45L, 46L, 47L, 47L),
x = c(1L, 2L, 1L, 3L, 3L))
with(d, as.data.frame(table(age,x)))

which gives:
  age x Freq
1  45 11
2  46 11
3  47 10
4  45 21
5  46 20
6  47 20
7  45 30
8  46 30
9  47 32

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 12, 2020 at 1:12 PM stefan.d...@gmail.com 
wrote:

> well, if I think about, its actually a simple frequency table grouped
> by age. but it should be usable a matrix or data frame.
>
> On Wed, Feb 12, 2020 at 9:48 PM  wrote:
> >
> > So a pivot table?
> >
> > On 12 Feb 2020 20:39, stefan.d...@gmail.com wrote:
> >
> > Dear All,
> >
> > I have a seemingly standard problem to which I somehow I do  not find
> > a simple solution. I have individual level data where x is a
> > categorical variable with 3 categories which I would like to aggregate
> > by age.
> >
> > age x
> > 45   1
> > 45   2
> > 46   1
> > 47   3
> > 47   3
> > and so on.
> >
> > It should after transformation look like that
> >
> > age x_1 x_2 x_3
> > 451 0   1
> > 461 0   0
> > 47 00   2
> >
> > Basically to calculate prevalences by age categories.
> >
> > Thanks for any pointers!
> >
> > Cheers!
> >
> > __
> > 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] N Sizes between Pairs of Columns using cor(, , , use = 'pairwise')

2020-01-21 Thread William Dunlap via R-help
crossprod(!is.na(tmp))

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Jan 21, 2020 at 11:56 AM Doran, Harold  wrote:

> I'm trying to find an efficient way to find the N size on correlations
> produced when using the pairwise option in cor().
>
> Here is a sample to illustrate:
>
> ### Create a sample data frame
> tmp <- data.frame(v1 = rnorm(10), v2 = rnorm(10), v3 = rnorm(10), v4 =
> rnorm(10))
>
> ### Create some random missingness
> for(i in 1:4) tmp[sample(1:10, 2, replace = FALSE), i] <- NA
>
> ### Correlate
> cor(tmp, use = 'pairwise')
>
> Now, a REALLY bad idea would be this (but conceptually it illustrates what
> I want)
>
> ### Identify all column pairs
> pairs <- combn(4,2)
>
> ### Now, write code to loop over each pair of columns and identify where
> both rows are TRUE
> !is.na(tmp[, pairs[,1]])
>
> Of course doing this when the number of pairwise combinations is silly.
> So, hmmm, I don't see as a by-product of the cor() function N sizes, and
> certainly looping over pairs of columns would be doable, but not efficient,
> but any suggestions on this?
>
> Thanks,
> Harold
>
> __
> 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 does one pass arguments to a function, such as coxph, that itself is inside a function?

2019-12-16 Thread William Dunlap via R-help
You can use substitute() to fiddle with the formula.  The following shows
how to do it using lm() instead of coxph(), but the manipulations are the
same.  It also has an 'envir' argument in case the formula depends on
anything in the callers enviroment.  The 'substitute(data)' is make the
printouts prettier.

f <- function (response, data, envir = parent.frame())
{
formula <- eval(substitute(response ~ X), envir = envir)
eval(as.call(list(quote(lm), formula, data = substitute(data))),
envir = envir)
}

> d <- data.frame(check.names=FALSE, "Y-one"=1:10, "Y-two"=sqrt(1:10),
X=log(1:10))
> lm(`Y-one` ~ X, data=d)

Call:
lm(formula = `Y-one` ~ X, data = d)

Coefficients:
(Intercept)X
-0.4371   3.9307

> f(`Y-one`, data=d)

Call:
lm(formula = `Y-one` ~ X, data = d)

Coefficients:
(Intercept)X
-0.4371   3.9307
> g <- function() {
+ Y3 <- 1/(1:10)
+ f(Y3, data=d)
+ }
> g()

Call:
lm(formula = Y3 ~ X, data = d)

Coefficients:
(Intercept)X
 0.8338  -0.3581



E.g.,
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Dec 16, 2019 at 10:12 AM Sorkin, John 
wrote:

> Question summary: How does one pass arguments to a function, such as
> coxph, that itself is inside a function.
>
> I am trying to write a function that will allow me to call coxph using
> different outcome and time variables. The coxph works when the coxph is NOT
> contained in a larger function (which passes the outcome and time variable
> to  use), but does not work when coxph is contained in a  larger funciton.
>
> My code:
>
> fit0 <-
> coxph(Surv(FUtime,Death)~Age_in_years_at_A1_max+factor(Diabetes)+factor(CKD_stage)+
>
>  factor(Phase1_first),data=mydata)
> summary(fit0)
>
> this works:
>
> Call:
> coxph(formula = Surv(FUtime, Death) ~ Age_in_years_at_A1_max +
> factor(Diabetes) + factor(CKD_stage) +
> factor(Phase1_first),
> data = mydata)
>
>   n= 350, number of events= 56
>
>coef exp(coef) se(coef)  z Pr(>|z|)
> Age_in_years_at_A1_max  0.04618   1.04727  0.01384  3.338 0.000845 ***
> factor(Diabetes)1   0.12247   1.13029  0.28282  0.433 0.664991
> factor(CKD_stage)3 -0.28418   0.75263  0.38744 -0.733 0.463261
> factor(CKD_stage)4  0.33938   1.40407  0.36583  0.928 0.353572
> factor(CKD_stage)5  0.97121   2.64115  0.40171  2.418 0.015618 *
> factor(Phase1_first)1   0.02204   1.02229  0.29713  0.074 0.940868
>
> other output deleted.
>
> But this code does not work:
>
> doit <- function(time,outcome,data){
>   fit0 <-
>
> coxph(Surv(time,outcome)~Age_in_years_at_A1_max+factor(Diabetes)+factor(CKD_stage)+factor(Phase1_first),data=data)
>   print(summary(fit0))
> }
> doit(FUtime,Death,mydata)
>
>  Error in Surv(time, outcome) : object 'FUtime' not found
>
> I am certain I have a scoping problem, but I don't know how to solve it.
>
> John David Sorkin M.D., Ph.D.
>
> Professor of Medicine
>
> Chief, Biostatistics and Informatics
>
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine
>
> Baltimore VA Medical Center
>
> 10 North Greene Street
>
> GRECC (BT/18/GR)
>
> Baltimore, MD 21201-1524
>
> (Phone) 410-605-7119
>
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
>
>
> __
> 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] table and unique seems to behave differently

2019-12-10 Thread William Dunlap via R-help
You can use save(ascii=TRUE,...) to make an ascii-only RData file that you
can include in the mail message.  E.g.,

> x <- c(3.4, 3.4 + 1e-15)
> save(x, ascii=TRUE, file=stdout())
RDA3
A
3
198145
197888
5
UTF-8
1026
1
262153
1
x
14
2
3.4
3.401
254

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Dec 10, 2019 at 8:37 AM Alain Guillet 
wrote:

> Another finding for me today: dput doesn't write exactly the vector that
> creates the problem. I could use an RData file but I think it is forbidden
> in this mailing list...
>
>
> Alain
> 
> De : Chris Evans 
> Envoyé : mardi 10 décembre 2019 15:41
> À : Alain Guillet 
> Cc : r-help@r-project.org 
> Objet : Re: [R] table and unique seems to behave differently
>
> This doesn't answer your question but I get exactly the same vector of
> length 210 with unique(toto) and names(table(toto)) using the same version
> of R that you are and I can't see any obvious reason why you wouldn't but
> when I hit things like that it tends to be that one version is string with
> initial or trailing spaces or a character set issue.  I can't see that
> those apply here but it's all I could imagine without racking my poor old
> brains much more.
>
> Good luck finding the answer!
>
> Chris
>
> - Original Message -
> > From: "Alain Guillet" 
> > To: r-help@r-project.org
> > Sent: Tuesday, 10 December, 2019 09:53:29
> > Subject: [R] table and unique seems to behave differently
>
> > Hi,
> >
> > I have a vector (see below the dput) and I use unique on it to get unique
> > values. If I then sort the result of the vector obtained by unique, I
> see some
> > elements that look like identical. I suspect it could be a matter of
> rounded
> > values but table gives a different result: unlike unique output which
> contains
> > "3.4  3.4", table has only one cell for 3.4.
> >
> > Can anybody know why I get results that look like incoherent between the
> two
> > functions?
> >
> >
> > Best regards,
> > Alain Guillet
> >
> > --
> > platform   x86_64-pc-linux-gnu
> > arch   x86_64
> > os linux-gnu
> > system x86_64, linux-gnu
> > status
> > major  3
> > minor  6.1
> > year   2019
> > month  07
> > day05
> > svn rev76782
> > language   R
> > version.string R version 3.6.1 (2019-07-05)
> > nickname   Action of the Toes
> > --
> >> dput(toto)
> > c(2.5, 2.6, 2.6, 2.6, 2.6, 2.7, 2.7, 2.7, 2.7, 2.7, 2.7, 2.8,
> > 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.8, 2.9, 2.9, 2.9, 2.9, 2.9,
> > 2.9, 2.9, 2.9, 3, 3, 3, 3, 3, 3, 3, 3, 3.1, 3.1, 3.1, 3.1, 3.1,
> > 3.1, 3.1, 3.1, 3.1, 3.1, 3.1, 3.1, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2,
> > 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.3, 3.3, 3.3, 3.3, 3.3, 3.3,
> > 3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.4, 3.4, 3.4, 3.4, 3.4, 3.4,
> > 3.4, 3.4, 3.4, 3.4, 3.4, 3.4, 3.4, 3.4, 3.5, 3.5, 3.5, 3.5, 3.5,
> > 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.6, 3.6, 3.6,
> > 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6,
> > 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.6, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7,
> > 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7,
> > 3.7, 3.7, 3.7, 3.7, 3.7, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8,
> > 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8,
> > 3.8, 3.8, 3.8, 3.8, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9,
> > 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9,
> > 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 3.9, 4, 4, 4, 4, 4, 4, 4, 4, 4,
> > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
> > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1,
> > 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1,
> > 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1, 4.1,
> > 4.1, 4.1, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2,
> > 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2,
> > 4.2, 4.2, 4.2, 4.2, 4.2, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3,
> > 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3,
> > 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.4, 4.4, 4.4, 4.4,
> > 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4,
> > 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4,
> > 4.4, 4.4, 4.4, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5,
> > 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5,
> > 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5,
> > 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.5, 4.6,
> > 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6,
> > 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6,
> > 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6,
> > 4.6, 4.6, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7,
> > 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7, 4.7,
> 

Re: [R] Error in FUN(X[[i]], ...) : subscript out of bounds

2019-12-04 Thread William Dunlap via R-help
In your fit_bayes function, you have
   getTrainPerf(mod)[, "TrainRMSE"]
What are the column name of the output of getTrainPerf(mod)?
   print(colnames(getTrainPerf(mod)))
You can home in on the problem faster if you call
   traceback()
immediately after the error.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Dec 4, 2019 at 3:38 AM Neha gupta  wrote:

> Hi , I know nobody will respond to my query as I asked few in the past and
> no answer received for any of my questions. However, I am asking here with
> the hope it will get responded.
>
> I am using bayesian optimization to tune the parameter of mtry for random
> forest but it gives me the error: Error in FUN(X[[i]], ...) : subscript out
> of bounds
>
> I am using the following code:
>
> fit_bayes <- function(mtry) {
>   ## Use the same model code but for a single (C, sigma) pair.
>   mod <- train(Effort ~ ., data = tr,
>method = "rf",
>preProc = c("center", "scale", "zv"),
>metric = "RMSE",
>trControl = ctrl,
>tuneGrid = data.frame(C = 10^(mtry)))
>
>   list(Score = -getTrainPerf(mod)[, "TrainRMSE"], Pred = 0)
> }
>
>
> library(rBayesianOptimization)
>
> bounds <- list(mtry = c(-2,  5)
>
>
> set.seed(8606)
> bo_search <- BayesianOptimization(fit_bayes,
>   bounds = bounds,
>   init_points = 10,
>   n_iter = 100,
>   acq = "ucb",
>   kappa = 1,
>   eps = 0.0)
> bo_search
>
> [[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] Can file size affect how na.strings operates in a read.table call?

2019-11-14 Thread William Dunlap via R-help
read.table (and friends) also have the strip.white argument:

> s <- "A,B,C\n0,0,0\n1,-99,-99\n2,-99 ,-99\n3, -99, -99\n"
> read.csv(text=s, header=TRUE, na.strings="-99", strip.white=TRUE)
  A  B  C
1 0  0  0
2 1 NA NA
3 2 NA NA
4 3 NA NA
> read.csv(text=s, header=TRUE, na.strings="-99", strip.white=FALSE)
  A   B   C
1 0   0   0
2 1  NA  NA
3 2 -99  NA
4 3 -99 -99

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Nov 14, 2019 at 8:35 AM Jeff Newmiller 
wrote:

> Consider the following sample:
>
> #
> s <- "A,B,C
> 0,0,0
> 1,-99,-99
> 2,-99 ,-99
> 3, -99, -99
> "
>
> dta_notok <- read.csv( text = s
>   , header=TRUE
>   , na.strings = c( "-99", "" )
>   )
>
> dta_ok <- read.csv( text = s
>, header=TRUE
>, na.strings = c( "-99", " -99"
>, "-99 ", ""
>)
>)
>
> library(data.table)
>
> fdt_ok <- fread( text = s, na.strings=c( "-99", "" ) )
> fdta_ok <- as.data.frame( fdt_ok )
> #
>
> Leading and trailing spaces cause problems. The data.table::fread function
> has a strip.white argument that defaults to TRUE, but the resulting object
> is a data.table which has different semantics than a data.frame.
>
> On Thu, 14 Nov 2019, Sebastien Bihorel wrote:
>
> > The data file is a csv file. Some text variables contain spaces.
> >
> > "Check for extraneous spaces"
> > Are there specific locations that would be more critical than others?
> >
> >
> >
> 
> > From: Jeff Newmiller 
> > Sent: Thursday, November 14, 2019 10:52
> > To: Sebastien Bihorel ; Sebastien
> > Bihorel via R-help ; r-help@r-project.org
> > 
> > Subject: Re: [R] Can file size affect how na.strings operates in a
> > read.table call?
> > Check for extraneous spaces. You may need more variations of the
> na.strings.
> >
> > On November 14, 2019 7:40:42 AM PST, Sebastien Bihorel via R-help
> >  wrote:
> > >Hi,
> > >
> > >I have this generic function to read ASCII data files. It is
> > >essentially a wrapper around the read.table function. My function is
> > >used in a large variety of situations and has no a priori knowledge
> > >about the data file it is asked to read. Nothing is known about file
> > >size, variable types, variable names, or data table dimensions.
> > >
> > >One argument of my function is na.strings which is passed down to
> > >read.table.
> > >
> > >Recently, a user tried to read a data file of ~ 80 Mo (~ 93000 rows by
> > >~ 160 columns) using na.strings = c('-99', '.') with the intention of
> > >interpreting '.' and '-99'
> > >strings as the internal missing data NA. Dots were converted to NA
> > >appropriately. However, not all -99 values in the data were interpreted
> > >as NA. In some variables, -99 were converted to NA, while in others -99
> > >was read as a number. More surprisingly, when the data file was cut in
> > >smaller chunks (ie, by dropping either rows or columns) saved in
> > >multiple files, the function calls applied on the new data files
> > >resulted in the correct conversion of the -99 values into NAs.
> > >
> > >In all cases, the data frames produced by read.table contained the
> > >expected number of records.
> > >
> > >While, on face value, it appears that file size affects how the
> > >na.strings argument operates, I wondering if there is something else at
> > >play here.
> > >
> > >Unfortunately, I cannot share the data file for confidentiality reason
> > >but was wondering if you could suggest some checks I could perform to
> > >get to the bottom on this issue.
> > >
> > >Thank you in advance for your help and sorry for the lack of
> > >reproducible example.
> > >
> > >
> > >__
> > >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.
> >
> >
>
> ---
> 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, 

Re: [R] using xpath with xml2

2019-11-12 Thread William Dunlap via R-help
> xml_ns(daymet)
d1<-> http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0
xlink <-> http://www.w3.org/1999/xlink
> daymet %>% xml2::xml_find_all(xpath = "d1:dataset")
{xml_nodeset (1)}
[1]  https://thredds.daac.ornl.gov/thredds/catalog/ornldaac/1328/catalog.xml;
>
> # run the following to show the node in a browser
> # httr::BROWSE(daymet_uri)
>
> daymet <- httr::GET(daymet_uri) %>%
>   httr::content(type = "text/xml", encoding = "UTF-8")
>
> # list the children "service" and "dataset"
> daymet %>% xml2::xml_children()
> #{xml_nodeset (2)}
> #[1] \n   name="odap" #serviceTyp ...
> #[2]  #
> # according to this tutorial we should find 'dataset'
> # https://www.w3schools.com/xml/xpath_syntax.asp
> daymet %>% xml2::xml_find_all(xpath = "//dataset")
> # {xml_nodeset (0)}
>
> # I have also tried every other xpath combination I think of e.g.
> #   ".//dataset", "./dataset", "/dataset" and "dataset"
> # They each yield an empty nodeset
>
> ### END
>
> > sessionInfo()
>
> R version 3.5.1 (2018-07-02)
> Platform: x86_64-redhat-linux-gnu (64-bit)
> Running under: CentOS Linux 7 (Core)
>
> Matrix products: default
> BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods
> [7] base
>
> other attached packages:
> [1] magrittr_1.5 httr_1.4.1   xml2_1.2.2
>
> loaded via a namespace (and not attached):
> [1] compiler_3.5.1 R6_2.4.0   tools_3.5.1curl_4.2
> [5] yaml_2.2.0 Rcpp_1.0.3
>
>
> Thanks,
> Ben
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
> Ecological Forecasting: https://eco.bigelow.org/
>
> __
> 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] problem in WRS2

2019-11-07 Thread William Dunlap via R-help
You can get this error if one of the explanatory variables is not a
factor.  E.g.
> WRS2::t2way(y ~ x1 * x2, data =
expand.grid(y=11:12,x1=letters[11:13],x2=21:24))
Error in x[[grp[i]]] :
  attempt to select less than one element in get1index

The immediate cause is that t2way uses 1:p instead of seq_len(p) when p may
be zero, but I suspect that the code should be converting some things to
factors so p cannot be zero.  Take this up with the package's maintainer.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Nov 6, 2019 at 1:58 PM greg holly  wrote:

> I got the following error message after running  t2way(y ~ Grup*Time, data
> = cp)
>   Error in x[[grp[i]]] :
>   attempt to select less than one element in get1index
>
> a part of the data is given below. Your help is highly appreciated.
>
> Greg
>
> > head(cp)
>   Birey Grup Time y
> 1 11  Cp1 0.7916386
> 2 11  Cp3 1.7463777
> 3 11  Cp7 1.2008390
> 4 11 Cp14 0.6311380
> 5 11 Cp21 2.1563557
> 6 11 Cp28 1.2008390
>
> [[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] " Error in firstnonmiss:lastnonmiss : argument of length 0 "

2019-10-30 Thread William Dunlap via R-help
The length(x)>dt2 requirement is not quite right - it is only required for
one branch of your if statement.  Figure out the assumptions for each
branch of the code and put stopifnot calls in each branch.  Or leave them
out and debug later.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Oct 30, 2019 at 5:13 PM  wrote:

> Thanks for your suggestions. I have tried them all, with no success.
>
> William's looked quite promising. I put in the
> stopifnot(is.numeric(x), NCOL(x)==1, length(x)>dt2)
> statement and it detected the problem:
> length(x) > dt2 is not TRUE
> Then I changed all the references to vseries to the [[j]]
> notation:
> vseries[,j] became vseries[[j]] and
> vseries$REF_DATE became vseries[[1]]
> But I still got the same error statement from stopifnot:
> length(x) > dt2 is not TRUE
>
> I am quite at a loss on this one. Any other suggestions? Maybe I should
> just take a completely different approach of some kind?
>
> Philip
>
> On 2019-10-30 12:58, William Dunlap wrote:
> > Your EXTEND() function appears to expect that its 'x' argument will be
> > a numeric vector, but you pass it a one-column tibble.  Hence
> > length(x) is 1 and things go downhill from there.
> >
> > I like to start such functions with a long stopifnot() statement that
> > does a quick check of inputs.  E.g.,
> >
> > stopifnot(is.numeric(x), NCOL(x)==1, length(x)>dt2)
> >
> > Use vseries1[,j,drop=TRUE] or vseries1[[j]] to extract a single column
> > from the tibble 'vseries1'.  vseries1[,1] will return a one-column
> > tibble.
> >
> > Bill Dunlap
> > TIBCO Software
> > wdunlap tibco.com [2]
> >
> > On Wed, Oct 30, 2019 at 5:25 AM  wrote:
> >
> >> Thanks for the suggestion Rui, but no, this will not remove the
> >> error.
> >> In fact, if I drop the second term entirely as in:
> >>
> >> if ( (!is.na [1](dts[1,j-1])) ) {
> >>
> >> then I still get the error. I have been unable to find a
> >> work-around.
> >>
> >> Philip
> >>
> >> On 2019-10-30 05:17, Rui Barradas wrote:
> >>> Hello,
> >>>
> >>> Is this as simple as
> >>>
> >>>
> >>> if ( (!is.na [1](dts[1,j-1])) & (!is.na [1](dts[3,j-1])) ) {
> >>>
> >>>
> >>> (change the logical operator from '|' to '&')?
> >>> The result vseries1 still has some NA's at the end of some of its
> >>> series.
> >>>
> >>> Hope this helps,
> >>>
> >>> Rui Barradas
> >>>
> >>> Às 02:05 de 30/10/19, p...@philipsmith.ca escreveu:
> >>>> I am having a problem that generates the error message: " Error
> >> in
> >>>> firstnonmiss:lastnonmiss : argument of length 0 ". There is an
> >> article
> >>>> on this in stackoverflow, but I have been unable to understand it
> >> well
> >>>> enough to solve my problem. Essentially, I have a data frame with
> >> 41
> >>>> indicator series and some of the series have missing values (NAs)
> >> at
> >>>> the beginning and/or the end. I want to fill in the missing
> >> values
> >>>> using ARIMA models, via the forecast() function. It works when I
> >> use
> >>>> my EXTEND function on a single series, but it fails when I try to
> >> loop
> >>>> through all 41 series. Here is a reproducible example. Thanks for
> >> any
> >>>> advice.
> >>>>
> >>>> # Reproducible example
> >>>> # " Error in firstnonmiss:lastnonmiss : argument of length 0 "
> >>>> # See also stackoverflow:
> >>>>
> >>
> >
> https://stackoverflow.com/questions/27350636/r-argument-is-of-length-zero-in-if-statement
> >>
> >>>> library(forecast)
> >>>> library(lubridate)
> >>>> vseries <- dget("vseries.txt") # data frame containing REF_DATE
> >> and 41
> >>>> "indicator" vectors
> >>>> dts <- dget("dts.txt") # data frame recording where NAs are in
> >> vseries
> >>>> - they will be replaced
> >>>> testcase1 <- dget("testcase1.txt") # a vector for use in testing
> >>>> # Function to fill in missing values (NAs) using ARIMA forecasts
> >> and
> >>>> backcasts
> >>>> EXTEND <-
> >> function(x,REF_DATE,dt1,dt2,dt3,dt4,first_date,

Re: [R] " Error in firstnonmiss:lastnonmiss : argument of length 0 "

2019-10-30 Thread William Dunlap via R-help
Using NROW(x) instead of length(x) is fine, but it won't fix the problem
that this function won't work if given a tibble.  E.g., for a tibble t,
rev(t) is identical to t.

 revx <- ts(rev(x),frequency=12)
 revx <- revx[1:(NRngt$(revx)-dt2)]
 fc <- forecast(auto.arima(revx),bfct)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Oct 30, 2019 at 10:31 AM Rui Barradas  wrote:

> Hello,
>
> Another option that prevents
>
> length(x) == 1
>
> is to use NROW(x) instead of length(x).
>
> Hope this helps,
>
> Rui Barradas
>
> Às 16:58 de 30/10/19, William Dunlap escreveu:
> > Your EXTEND() function appears to expect that its 'x' argument will be a
> > numeric vector, but you pass it a one-column tibble.  Hence length(x) is
> > 1 and things go downhill from there.
> >
> > I like to start such functions with a long stopifnot() statement that
> > does a quick check of inputs.  E.g.,
> >
> > stopifnot(is.numeric(x), NCOL(x)==1, length(x)>dt2)
> >
> > Use vseries1[,j,drop=TRUE] or vseries1[[j]] to extract a single column
> > from the tibble 'vseries1'.  vseries1[,1] will return a one-column
> tibble.
> >
> > Bill Dunlap
> > TIBCO Software
> > wdunlap tibco.com <http://tibco.com>
> >
> >
> > On Wed, Oct 30, 2019 at 5:25 AM  > <mailto:p...@philipsmith.ca>> wrote:
> >
> > Thanks for the suggestion Rui, but no, this will not remove the
> error.
> > In fact, if I drop the second term entirely as in:
> >
> > if ( (!is.na <http://is.na>(dts[1,j-1])) ) {
> >
> > then I still get the error. I have been unable to find a work-around.
> >
> > Philip
> >
> >
> > On 2019-10-30 05:17, Rui Barradas wrote:
> >  > Hello,
> >  >
> >  > Is this as simple as
> >  >
> >  >
> >  > if ( (!is.na <http://is.na>(dts[1,j-1])) & (!is.na
> > <http://is.na>(dts[3,j-1])) ) {
> >  >
> >  >
> >  > (change the logical operator from '|' to '&')?
> >  > The result vseries1 still has some NA's at the end of some of its
> >  > series.
> >  >
> >  > Hope this helps,
> >  >
> >  > Rui Barradas
> >  >
> >  > Às 02:05 de 30/10/19, p...@philipsmith.ca
> > <mailto:p...@philipsmith.ca> escreveu:
> >  >> I am having a problem that generates the error message: " Error
> in
> >  >> firstnonmiss:lastnonmiss : argument of length 0 ". There is an
> > article
> >  >> on this in stackoverflow, but I have been unable to understand
> > it well
> >  >> enough to solve my problem. Essentially, I have a data frame
> > with 41
> >  >> indicator series and some of the series have missing values
> > (NAs) at
> >  >> the beginning and/or the end. I want to fill in the missing
> values
> >  >> using ARIMA models, via the forecast() function. It works when I
> > use
> >  >> my EXTEND function on a single series, but it fails when I try
> > to loop
> >  >> through all 41 series. Here is a reproducible example. Thanks
> > for any
> >  >> advice.
> >  >>
> >  >> # Reproducible example
> >  >> # " Error in firstnonmiss:lastnonmiss : argument of length 0 "
> >  >> # See also stackoverflow:
> >  >>
> >
> https://stackoverflow.com/questions/27350636/r-argument-is-of-length-zero-in-if-statement
> >
> >  >> library(forecast)
> >  >> library(lubridate)
> >  >> vseries <- dget("vseries.txt") # data frame containing REF_DATE
> > and 41
> >  >> "indicator" vectors
> >  >> dts <- dget("dts.txt") # data frame recording where NAs are in
> > vseries
> >  >> - they will be replaced
> >  >> testcase1 <- dget("testcase1.txt") # a vector for use in testing
> >  >> # Function to fill in missing values (NAs) using ARIMA forecasts
> > and
> >  >> backcasts
> >  >> EXTEND <-
> > function(x,REF_DATE,dt1,dt2,dt3,dt4,first_date,last_date) {
> >  >>if (!is.na <http://is.na>(dt1)) {
> >  >>  bfct = dt2-dt1+1 # number of months to backcast
> >  >>  revx <- ts(rev(x),frequency=

Re: [R] " Error in firstnonmiss:lastnonmiss : argument of length 0 "

2019-10-30 Thread William Dunlap via R-help
Your EXTEND() function appears to expect that its 'x' argument will be a
numeric vector, but you pass it a one-column tibble.  Hence length(x) is 1
and things go downhill from there.

I like to start such functions with a long stopifnot() statement that does
a quick check of inputs.  E.g.,

stopifnot(is.numeric(x), NCOL(x)==1, length(x)>dt2)

Use vseries1[,j,drop=TRUE] or vseries1[[j]] to extract a single column from
the tibble 'vseries1'.  vseries1[,1] will return a one-column tibble.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Oct 30, 2019 at 5:25 AM  wrote:

> Thanks for the suggestion Rui, but no, this will not remove the error.
> In fact, if I drop the second term entirely as in:
>
> if ( (!is.na(dts[1,j-1])) ) {
>
> then I still get the error. I have been unable to find a work-around.
>
> Philip
>
>
> On 2019-10-30 05:17, Rui Barradas wrote:
> > Hello,
> >
> > Is this as simple as
> >
> >
> > if ( (!is.na(dts[1,j-1])) & (!is.na(dts[3,j-1])) ) {
> >
> >
> > (change the logical operator from '|' to '&')?
> > The result vseries1 still has some NA's at the end of some of its
> > series.
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > Às 02:05 de 30/10/19, p...@philipsmith.ca escreveu:
> >> I am having a problem that generates the error message: " Error in
> >> firstnonmiss:lastnonmiss : argument of length 0 ". There is an article
> >> on this in stackoverflow, but I have been unable to understand it well
> >> enough to solve my problem. Essentially, I have a data frame with 41
> >> indicator series and some of the series have missing values (NAs) at
> >> the beginning and/or the end. I want to fill in the missing values
> >> using ARIMA models, via the forecast() function. It works when I use
> >> my EXTEND function on a single series, but it fails when I try to loop
> >> through all 41 series. Here is a reproducible example. Thanks for any
> >> advice.
> >>
> >> # Reproducible example
> >> # " Error in firstnonmiss:lastnonmiss : argument of length 0 "
> >> # See also stackoverflow:
> >>
> https://stackoverflow.com/questions/27350636/r-argument-is-of-length-zero-in-if-statement
> >> library(forecast)
> >> library(lubridate)
> >> vseries <- dget("vseries.txt") # data frame containing REF_DATE and 41
> >> "indicator" vectors
> >> dts <- dget("dts.txt") # data frame recording where NAs are in vseries
> >> - they will be replaced
> >> testcase1 <- dget("testcase1.txt") # a vector for use in testing
> >> # Function to fill in missing values (NAs) using ARIMA forecasts and
> >> backcasts
> >> EXTEND <- function(x,REF_DATE,dt1,dt2,dt3,dt4,first_date,last_date) {
> >>if (!is.na(dt1)) {
> >>  bfct = dt2-dt1+1 # number of months to backcast
> >>  revx <- ts(rev(x),frequency=12)
> >>  revx <- revx[1:(length(revx)-dt2)]
> >>  fc <- forecast(auto.arima(revx),bfct)
> >>  revx1 <- c(revx,fc$mean) # extend with forecasts (in fc$mean)
> >>  m <- month(as.POSIXlt(first_date,format="%Y-%m-%d"))
> >>  y <- year(as.POSIXlt(first_date,format="%Y-%m-%d"))
> >>  x <- as.numeric(ts(rev(revx1),start=c(y,m),frequency=12))
> >>}
> >>if (!is.na(dt3)) {
> >>  ffct <- dt4-dt3+1 # number of months to forecast
> >>  x <- x[1:(dt3-1)]
> >>  fc <- forecast(auto.arima(x),ffct)
> >>  x <- c(x,fc$mean)
> >>}
> >>return(x)
> >> }
> >> # Test EXTEND function with a single vector - apparently it works
> >> (testcase1_extended <- EXTEND(testcase1,vseries$REF_DATE,1,3,222,223,
> >> vseries$REF_DATE[1],vseries$REF_DATE[length(vseries$REF_DATE)]))
> >> View(cbind(testcase1,testcase1_extended))
> >> # Now use EXTEND to fill in the missing values in all 41 indicators in
> >> vseries
> >> # Data frame dts has NAs where no extension is required, integer
> >> values showing where to start and
> >> # where to end when extensions are required. Store extended series in
> >> vseries1.
> >> vseries1 <- vseries
> >> for (j in 2:(ncol(vseries))) { # j starts at 2 because column 1 in
> >> vseries is REF_DATE
> >>if ( (!is.na(dts[1,j-1])) | (!is.na(dts[3,j-1])) ) {
> >>  vseries1[,j] <-
> >>
> EXTEND(vseries[,j],vseries$REF_DATE,dts[1,j-1],dts[2,j-1],dts[3,j-1],dts[4,j-1],
>
> >> vseries$REF_DATE[1],vseries$REF_DATE[length(vseries$REF_DATE)])
> >>}
> >> }
> >> View(vseries)
> >> View(vseries1)
> >>
> >> dput() output for vseries:
> >>
> >> structure(list(REF_DATE = c("2001-01-01", "2001-02-01", "2001-03-01",
> >> "2001-04-01", "2001-05-01", "2001-06-01", "2001-07-01", "2001-08-01",
> >> "2001-09-01", "2001-10-01", "2001-11-01", "2001-12-01", "2002-01-01",
> >> "2002-02-01", "2002-03-01", "2002-04-01", "2002-05-01", "2002-06-01",
> >> "2002-07-01", "2002-08-01", "2002-09-01", "2002-10-01", "2002-11-01",
> >> "2002-12-01", "2003-01-01", "2003-02-01", "2003-03-01", "2003-04-01",
> >> "2003-05-01", "2003-06-01", "2003-07-01", "2003-08-01", "2003-09-01",
> >> "2003-10-01", "2003-11-01", "2003-12-01", "2004-01-01", "2004-02-01",
> >> "2004-03-01", "2004-04-01", 

Re: [R] Error when using qvalue function

2019-10-28 Thread William Dunlap via R-help
With qvalue-2.16.0 and R-3.6.1 many calls to qvalue::qvalue die in its call
to qvalue::pi0est.  E.g.,

> trace(smooth.spline, quote(cat("y=", deparse(y), "\n")))
Tracing function "smooth.spline" in package "stats"
[1] "smooth.spline"
> qvalue::pi0est(c(.01, .01, .06))
Tracing smooth.spline(lambda, pi0, df = smooth.df) on entry
y= c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,  NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,  NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_)
Error in smooth.spline(lambda, pi0, df = smooth.df) :
  missing or infinite values in inputs are not allowed

You should submit a bug report to
> packageDescription("qvalue")$URL
[1] "http://github.com/jdstorey/qvalue;

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Oct 28, 2019 at 3:13 PM Jim Lemon  wrote:

> Hi Ana,
> Seems to work without error for me:
>
> # installed qvalue_1.26.0 from CRAN archive
> library(qvalue)
>  pvals<-c(6.919239e-02,1.073784e-01,1.218613e-01,1.586202e-01,
>  1.370340e-01,3.452574e-02,2.545619e-01,1.676715e-02,8.571197e-01,
>  8.649025e-01,1.777414e-02,6.801867e-01,6.873085e-01,
>  1.276566e-01,5.907002e-02,2.343207e-02,2.078125e-02,6.404511e-02,
>  3.306593e-02,9.411259e-04,1.038989e-03,4.734674e-05,
>  3.422489e-05,5.606264e-05,6.322817e-02,1.291268e-02,3.452596e-03,
>  1.770753e-01,3.285821e-01,2.292055e-02,5.503168e-02,
>  6.940048e-01,3.638889e-03,6.799640e-01,1.301045e-02,6.794010e-01,
>  2.339327e-02,1.038529e-01,3.137687e-04,2.148050e-02,
>  1.783068e-01,1.764518e-01,6.386686e-03,1.670062e-02,3.220291e-01,
>  5.568613e-01,8.886102e-01,5.031040e-01,3.760079e-01,
>  6.638034e-02,9.419648e-03,5.885266e-03,1.539809e-02,5.296551e-03,
>  2.425230e-02,5.023091e-01,4.547284e-03,1.850796e-01,
>  9.389289e-02,6.544873e-03,3.031956e-03,7.772671e-03,9.073974e-03,
>  9.118352e-02,4.075408e-04,6.902206e-01,6.929767e-02,
>  1.897121e-02,6.693074e-02,1.111308e-02,1.286147e-02,4.515834e-02,
>  8.886941e-01,8.891051e-01,3.792846e-01,5.368898e-01,
>  2.323894e-01,3.220141e-01,7.320883e-02,9.642521e-03,6.024415e-01,
>  2.459322e-02,2.873351e-01,8.477168e-01,1.351068e-02,
>  1.053550e-01,4.812686e-01,1.404957e-01,9.835912e-02,4.373995e-01,
>  8.803856e-02)
> qval_obj=qvalue(pvals)
> qval_obj$pi0
> [1] 0.1981095
> pi1=1-qval_obj$pi0
> pi1
> [1] 0.8018905
>
> Jiim
>
> On Tue, Oct 29, 2019 at 8:45 AM Ana Marija 
> wrote:
> >
> > Hello,
> >
> > I am trying to calculate True Positive Rate, TPR with this procedure:
> >
> > pvals=q$METAge
> > qval_obj=qvalue(pvals) #is false discovery rate
> > pi1=1-qval_obj$pi0 #TPR
> > pi1  #TPR
> >
> > But I am getting this error:
> >
> > Error in smooth.spline(lambda, pi0, df = smooth.df) :
> >missing or infinite values in inputs are not allowed
> >
> > I have 91 p values and they look like this:
>
> __
> 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] "chi-square" | "chi-squared" | "chi squared" | "chi, square"

2019-10-19 Thread William Dunlap via R-help
Sigma squared or sigma square?  Hotelling's T-squared or T-square?

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sat, Oct 19, 2019 at 7:38 AM Therneau, Terry M., Ph.D. via R-help <
r-help@r-project.org> wrote:

> Martin,
>A fun question.
>
> Looking back at my oldest books, Feller (1950) used chi-square.
> Then I walked down the hall to our little statistics library and looked at
> Johnson and
> Kotz, "Continous Univariate Distributions", since each chapter therein has
> comments about
> the history of the distribution.
>
>   a.  They use 'chi-square' throughout their history section, tracing the
> distribution
> back to work in the 1800s.  But, those earliest papers apparently didn't
> name their
> results as chi- whatever, so an "origin" story didn't pan out.
>
>   b. They have 13 pages of references, and for fun I counted the occurence
> of variants.
> The majority of papers don't have the word in the title at all and the
> next most common is
> the Greek symbol. Here are the years of the others:
>
> chi-square:   73 43 65 80 86 73 82 73 69 69 78 64 64 86 65 86 82 82 76 82
> 88 81 74 77 87
> 86 93 69 60 88 88 80 77 41 59 79 31
> chi-squared: 72 76 82 83 89 79 69 67 77 78 69 77 83 88 87 89 78
> chi:  92 73 89 87
> chi-squares: 77 83
> chi-bar-square: 91
>
> There doesn't look to be a trend over time.  The 1922 Fisher reference
> uses the Greek
> symbol, by the way.
>
> Terry T
>
>
> [[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] Surprising Symbolic Model Formula Evaluations

2019-10-11 Thread William Dunlap via R-help
Look at what terms() (hence lm()) does with such formulae:
> str(terms(y~1*x))
Classes 'terms', 'formula'  language y ~ 1 * x
  ..- attr(*, "variables")= language list(y, x)
  ..- attr(*, "factors")= int(0)
  ..- attr(*, "term.labels")= chr(0)
  ..- attr(*, "order")= int(0)
  ..- attr(*, "intercept")= int 1
  ..- attr(*, "response")= int 1
  ..- attr(*, ".Environment")=
> coef(lm(y~1*x, data=data.frame(y=1:10,x=log2(1:10
(Intercept)
5.5


Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Oct 11, 2019 at 10:59 AM Richard M. Heiberger 
wrote:

> I can't duplicate your examples
> This is what I see
> > y ~ 1:x
> y ~ 1:x
>
> Please try again in a vanilla R session, and send a reproducible example.
> vanilla means start R from the operating system command line with
> R --vanilla
>
> this prevents any of your initialization files from being loaded.  See
> ?Startup
> for details.
>
> On Fri, Oct 11, 2019 at 1:05 PM Emi Tanaka 
> wrote:
> >
> > Hi,
> >
> > I'm wondering about some logics behind the following simplifications:
> >
> > y ~ 1:x simplifies to y ~ 1
> > y ~ x:1 simplifies to y ~ 1
> > y ~ x*1 simplifies to y ~ x
> > y ~ 1*x simplifies to y ~ 1
> >
> > Mainly I would have expected y ~ 1:x to simplify to y ~ x and the cross
> > operator to be invariant to order.
> >
> > I have some further surprising cases below that I'd also like to know
> more
> > about but just above will also be great.
> >
> > https://rpubs.com/emitanaka/unexpected-formula-eval
> >
> > Best,
> >
> > Emi
> >
> > *Dr. Emi Tanaka* | Lecturer in Statistics
> >
> > Faculty of Science, School of Mathematics and Statistics
> >
> >
> > Secretary, NSW Branch, Statistical Society of Australia
> > <
> https://www.meetup.com/NSW-Branch-of-the-Statistics-Society-of-Australia/>
> >
> > Social Media Coordinator, Central, International Biometrics Society
> > 
> >
> >
> > *THE UNIVERSITY OF SYDNEY*
> > 827, Carslaw F07 | The University of Sydney | NSW | 2006
> > *Phone:* +61 2 9351 3039
> > *Website:* * *https://emitanaka.github.io/
> > *Twitter: *@statsgen
> >
> > CRICOS 00026A
> > This email plus any attachments to it are confidential.
> > Any unauthorised use is strictly prohibited. If you receive this email in
> > error, please delete it and any attachments. Please think of our
> > environment and only print this e-mail if necessary.
> >
> > [[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.
>

[[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] Choosing specific Date Range from non-sequential Date

2019-09-09 Thread William Dunlap via R-help
To get a quick answer to your question you should provide a smallexample
that one can simply copy and paste into an R session.  It also helps to
show some details about how something does not work, more than " But it
didn't work."   E.g.,

d <- read.table(header=FALSE, text="1997-11-23 -2.91709629064653
1997-12-07 -0.960255426066815
1997-12-11 -1.98210752999868
1997-12-20 -1.10800598439855
1998-01-01 -1.00090115428118
1998-01-29 -1.03056081882709")
names(d) <- c("date", "measurement")
subset(d, date > "1997-12-15" & date < "1998-01-16")

which gave:

[1] datemeasurement
<0 rows> (or 0-length row.names)
Warning messages:
1: In Ops.factor(date, "1997-12-15") : ‘>’ not meaningful for factors
2: In Ops.factor(date, "1998-01-16") : ‘<’ not meaningful for factors

People seeing the call to read.table() and the warning messages from
subset() could quickly and confidently recommend adding
the colClasses=c("Date", "numeric") to the call to read.table.  Without
that information, both questioners and helpers become frustrated.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Sep 9, 2019 at 12:15 PM Ogbos Okike 
wrote:

> Dear Bert and Jeff,
> Thank you for looking at this.
> I am surprised my message was not in plain text. It has been
> configured to send message to the list in plain text earlier before.
>
> The data again please.
>
> 1997-11-23 -2.91709629064653
> 1997-12-07 -0.960255426066815
> 1997-12-11 -1.98210752999868
> 1997-12-20 -1.10800598439855
> 1998-01-01 -1.00090115428118
> 1998-01-29 -1.03056081882709
> 1998-03-27 -0.873243859498216
> 1998-04-09 -2.06378384750109
> 1998-04-12 -2.06826431469008
> 1998-04-19 -2.49834620746286
> 1998-05-02 -6.4357083781542
> 1998-05-17 -2.25359807972754
> 1998-05-21 -2.55799006865995
> 1999-08-22 -2.25114162617707
> 1999-08-25 -1.47905397376409
> 1999-09-05 -0.641589808755325
> 1999-09-09 -0.648954682695949
> 1999-09-13 -0.726364489272492
> 1999-09-16 -1.28445236942011
>
> The first column is  date and the second is another data of interest.
>
> The date is long but note sequential. Runs randomly from 1953 to 2019.
>
> I would like to select any range of date from year A to year B.
>
> Thank you again for your help.
> Best
> Ogbos
>
>
> On Mon, Sep 9, 2019 at 6:18 PM Jeff Newmiller 
> wrote:
> >
> > Or the column is not named "date", or it is a factor... and the question
> is not posted in plain text
> >
> > On September 9, 2019 9:55:48 AM PDT, Bert Gunter 
> wrote:
> > >I would guess that you first need to convert your textual dates to a
> > >date-time object via as.date, but as you failed to provide a
> > >reproducible
> > >example (e.g. via dput) I may be wrong. Maybe others may have greater
> > >insight.
> > >
> > >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 Mon, Sep 9, 2019 at 8:55 AM Ogbos Okike 
> > >wrote:
> > >
> > >> Dear Contributors,
> > >> I have a data frame of the form:
> > >> 1997-11-23 -2.91709629064653
> > >> 1997-12-07 -0.960255426066815
> > >> 1997-12-11 -1.98210752999868
> > >> 1997-12-20 -1.10800598439855
> > >> 1998-01-01 -1.00090115428118
> > >> 1998-01-29 -1.03056081882709
> > >> 1998-03-27 -0.873243859498216
> > >> 1998-04-09 -2.06378384750109
> > >> 1998-04-12 -2.06826431469008
> > >> 1998-04-19 -2.49834620746286
> > >> 1998-05-02 -6.4357083781542
> > >> 1998-05-17 -2.25359807972754
> > >> 1998-05-21 -2.55799006865995
> > >> 1999-08-22 -2.25114162617707
> > >> 1999-08-25 -1.47905397376409
> > >> 1999-09-05 -0.641589808755325
> > >> 1999-09-09 -0.648954682695949
> > >> 1999-09-13 -0.726364489272492
> > >> 1999-09-16 -1.28445236942011
> > >>
> > >> The events happen randomly and so the date is non-sequential. It run
> > >form
> > >> 1953 to 2019.
> > >>
> > >> I would like to select all the events/dates between 1998 to 2005.
> > >>
> > >> One of the things I tried is:
> > >> Year <- subset(MOSCFD50, date > "1998-01-01" & date < "2005-12-31").
> > >>
> > >> But it didn't work.
> > >>
> > >> I would be thankful if you could please redirect me.
> > >>
> > >> Thank you very much.
> > >> Best regards
> > >> Ogbos
> > >>
> > >> [[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 

Re: [R] R code: How to correct "Error in parse(text = x, keep.source = FALSE)" output in psych package using own dataset

2019-08-29 Thread William Dunlap via R-help
Element #2 of that output,  the empty fomula " F1=~  ", triggers the bug in
omegaSem.
omegaSem needs to ignore such entries in omega's output.  psych's author
should be able to fix things up.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Aug 29, 2019 at 12:31 PM Danilo Esteban Rodriguez Zapata <
danilo_rodrig...@cun.edu.co> wrote:

> well the output with the code that you refer is the following:
>
> > psych::omega(my.data)$model$lavaan
> [1] g =~
> +AUT_10_04+AUN_07_01+AUN_07_02+AUN_09_01+AUN_10_01+AUT_11_01+AUT_17_01+AUT_20_03+CRE_05_02+CRE_07_04+CRE_10_01+CRE_16_02+EFEC_03_07+EFEC_05+EFEC_09_02+EFEC_16_03+EVA_02_01+EVA_07_01+EVA_12_02+EVA_15_06+FLX_04_01+FLX_04_05+FLX_08_02+FLX_10_03+IDO_01_06+IDO_05_02+IDO_09_03+IDO_17_01+IE_01_03+IE_10_03+IE_13_03+IE_15_01+LC_07_03+LC_08_02+LC_11_03+LC_11_05+ME_02_03+ME_07_06+ME_09_01+ME_09_06+NEG_01_03+NEG_05_04+NEG_07_03+NEG_08_01+OP_03_05+OP_12_01+OP_14_01+OP_14_02+ORL_01_03+ORL_03_01+ORL_03_05+ORL_10_05+PER_08_02+PER_16_01+PER_19_06+PER_22_06+PLA_01_03+PLA_05_01+PLA_07_02+PLA_10_01+PLA_12_02+PLA_18_01+PR_06_02+PR_15_03+PR_25_01+PR_25_06+REL_09_05+REL_14_03+REL_14_06+REL_16_04+RS_02_03+RS_07_05+RS_08_05+RS_13_03+TF_03_01+TF_04_01+TF_10_03+TF_12_01+TRE_09_05+TRE_09_06+TRE_26_04+TRE_26_05
> [2] F1=~
>
>
>
>
>
>
>
>
>
>
> [3] F2=~  + AUN_07_02 + CRE_05_02 + CRE_07_04 + CRE_16_02 + EFEC_09_02 +
> EVA_12_02 + FLX_08_02 + IDO_01_06 + IDO_05_02 + LC_08_02 + LC_11_03 +
> LC_11_05 + ME_02_03 + ME_07_06 + ME_09_06 + NEG_07_03 + OP_03_05 + OP_14_01
> + OP_14_02 + ORL_01_03 + ORL_03_01 + PER_08_02 + PER_19_06 + PLA_05_01 +
> PLA_07_02 + PLA_10_01 + PLA_12_02 + PLA_18_01 + PR_06_02 + PR_15_03 +
> PR_25_01 + PR_25_06 + REL_14_06 + REL_16_04 + TF_04_01 + TF_10_03 +
> TRE_26_04 + TRE_26_05
>
>
>
>
> [4] F3=~  + AUT_10_04 + AUN_07_01 + AUN_09_01 + AUN_10_01 + AUT_11_01 +
> AUT_17_01 + AUT_20_03 + CRE_10_01 + EFEC_03_07 + EFEC_05 + EFEC_16_03 +
> EVA_02_01 + EVA_07_01 + EVA_15_06 + FLX_04_01 + FLX_04_05 + FLX_10_03 +
> IDO_09_03 + IDO_17_01 + IE_01_03 + IE_10_03 + IE_13_03 + IE_15_01 +
> LC_07_03 + ME_09_01 + NEG_01_03 + NEG_05_04 + NEG_08_01 + OP_12_01 +
> ORL_03_05 + ORL_10_05 + PER_16_01 + PER_22_06 + PLA_01_03 + REL_09_05 +
> REL_14_03 + RS_02_03 + RS_07_05 + RS_08_05 + RS_13_03 + TF_03_01 + TF_12_01
> + TRE_09_05 + TRE_09_06
>
>
>
> >
>
> El jue., 29 ago. 2019 a las 14:29, Danilo Esteban Rodriguez Zapata (<
> danilo_rodrig...@cun.edu.co>) escribió:
>
>> Dear William,
>>
>> Thank you for your answer, I would like to add some information that I
>> just obtained looking in different sites and forums. Someone there ask me
>> to create a fake data file, so I did that from my original data file. What
>> I did was open the .csv file with notepad and replace all the 4 for 5 and
>> the 2 for 1, then I saved the file again with no other changes. I also
>> searched for the "~" in the file and I found nothing.  Now with that file I
>> did the omegaSem() function and it worked succesfully, so the weird thing
>> here is that the omegaSem() function works with the fake data file, wich is
>> exactly the same as the original file, but recoding some answers as I said.
>>
>> It seems to be an issue with the file. When I replace, lets say, the 5
>> for 6 and make the omegaSem() again, it works. Then I replace back again
>> the 6 for 5 in all the data and the function doesn't works anymore.
>>
>> El jue., 29 ago. 2019 a las 12:33, William Dunlap ()
>> escribió:
>>
>>> > omegaSem(r9,n.obs=198)
>>> Error in parse(text = x, keep.source = FALSE) :
>>>   :2:0: unexpected end of input
>>>
>>> This error probably comes from calling factor("~") and
>>> psych::omegaSem(data) will do that if  all the columns in data are very
>>> highly correlated with one another.   In that case omega(data, nfactor=n)
>>> will not be able to find n factors in the data but it returns "~" in place
>>> of the factors that it could not find.  E.g.,
>>> > fakeData <- data.frame(A=1/(1:40), B=1/(2:41), C=1/(3:42), D=1/(4:43),
>>> E=1/(5:44))
>>> > cor(fakeData)
>>>   A B C D E
>>> A 1.000 0.9782320 0.9481293 0.9215071 0.8988962
>>> B 0.9782320 1.000 0.9932037 0.9811287 0.9684658
>>> C 0.9481293 0.9932037 1.000 0.9969157 0.9906838
>>> D 0.9215071 0.9811287 0.9969157 1.000 0.9983014
>>> E 0.8988962 0.9684658 0.9906838 0.9983014 1.000
>>> > psych::omegaSem(fakeData)
>>> Loading required namespace: lavaan
>>> Loading required namespace: GPArotati

Re: [R] R code: How to correct "Error in parse(text = x, keep.source = FALSE)" output in psych package using own dataset

2019-08-29 Thread William Dunlap via R-help
Please use 'reply to all' for responses to R-help reponses.

What do you get with your original data for
   psych::omega(my.data)$model$lavaan
?  Any entries like "F3=~"?

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Aug 29, 2019 at 12:05 PM Danilo Esteban Rodriguez Zapata <
danilo_rodrig...@cun.edu.co> wrote:

> Dear William,
>
> Thank you for your answer, I would like to add some information that I
> just obtained looking in different sites and forums. Someone there ask me
> to create a fake data file, so I did that from my original data file. What
> I did was open the .csv file with notepad and replace all the 4 for 5 and
> the 2 for 1, then I saved the file again with no other changes. I also
> searched for the "~" in the file and I found nothing.  Now with that file I
> did the omegaSem() function and it worked succesfully, so the weird thing
> here is that the omegaSem() function works with the fake data file, wich is
> exactly the same as the original file, but recoding some answers as I said.
>
> It seems to be an issue with the file. When I replace, lets say, the 5 for
> 6 and make the omegaSem() again, it works. Then I replace back again the 6
> for 5 in all the data and the function doesn't works anymore.
>
> El jue., 29 ago. 2019 a las 12:33, William Dunlap ()
> escribió:
>
>> > omegaSem(r9,n.obs=198)
>> Error in parse(text = x, keep.source = FALSE) :
>>   :2:0: unexpected end of input
>>
>> This error probably comes from calling factor("~") and
>> psych::omegaSem(data) will do that if  all the columns in data are very
>> highly correlated with one another.   In that case omega(data, nfactor=n)
>> will not be able to find n factors in the data but it returns "~" in place
>> of the factors that it could not find.  E.g.,
>> > fakeData <- data.frame(A=1/(1:40), B=1/(2:41), C=1/(3:42), D=1/(4:43),
>> E=1/(5:44))
>> > cor(fakeData)
>>   A B C D E
>> A 1.000 0.9782320 0.9481293 0.9215071 0.8988962
>> B 0.9782320 1.000 0.9932037 0.9811287 0.9684658
>> C 0.9481293 0.9932037 1.000 0.9969157 0.9906838
>> D 0.9215071 0.9811287 0.9969157 1.000 0.9983014
>> E 0.8988962 0.9684658 0.9906838 0.9983014 1.000
>> > psych::omegaSem(fakeData)
>> Loading required namespace: lavaan
>> Loading required namespace: GPArotation
>> In factor.stats, I could not find the RMSEA upper bound . Sorry about that
>> Error in parse(text = x, keep.source = FALSE) :
>>   :2:0: unexpected end of input
>> 1: ~
>>^
>> In addition: Warning message:
>> In cov2cor(t(w) %*% r %*% w) :
>>   diag(.) had 0 or NA entries; non-finite result is doubtful
>> > psych::omega(fakeData)$model$lavaan
>> In factor.stats, I could not find the RMSEA upper bound . Sorry about that
>> [1] g =~ +A+B+C+D+E   F1=~  + B + C + D + E F2=~  + A
>> [4] F3=~
>> Warning message:
>> In cov2cor(t(w) %*% r %*% w) :
>>   diag(.) had 0 or NA entries; non-finite result is doubtful
>>
>> You can get a result if you use nfactors=n where n is the number of the
>> good F entries in psych::omega()$model$lavaan:
>> > psych::omegaSem(fakeData, nfactors=2)
>> ...
>>
>> Measures of factor score adequacy
>>gF1*  F2*
>> Correlation of scores with factors 11.35  12.4284.45
>> Multiple R square of scores with factors  128.93 154.32  7131.98
>> Minimum correlation of factor score estimates 256.86 307.64 14262.96
>> ...
>> Does that work with your data?
>>
>> This is a problem that the maintainer of psych,
>> >   maintainer("psych")
>> [1] "William Revelle "
>> would like to know about.
>>
>>
>>
>>
>>
>>
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>>
>> On Thu, Aug 29, 2019 at 9:03 AM Danilo Esteban Rodriguez Zapata via
>> R-help  wrote:
>>
>>> This is a problem related to my last question referred to the omegaSem()
>>> function in the psych package (that is already solved because I realized
>>> that I was missing a variable assignment and because of that I had an
>>> 'object not found' error:
>>>
>>>
>>> https://stackoverflow.com/questions/57661750/one-of-the-omegasem-function-arguments-is-an-object-not-found
>>>
>>> I was trying to use that function following the guide to find McDonald's
>>> hierarchical Omega by Dr William Revelle:
>>>
>>> http://pers

Re: [R] R code: How to correct "Error in parse(text = x, keep.source = FALSE)" output in psych package using own dataset

2019-08-29 Thread William Dunlap via R-help
> omegaSem(r9,n.obs=198)
Error in parse(text = x, keep.source = FALSE) :
  :2:0: unexpected end of input

This error probably comes from calling factor("~") and
psych::omegaSem(data) will do that if  all the columns in data are very
highly correlated with one another.   In that case omega(data, nfactor=n)
will not be able to find n factors in the data but it returns "~" in place
of the factors that it could not find.  E.g.,
> fakeData <- data.frame(A=1/(1:40), B=1/(2:41), C=1/(3:42), D=1/(4:43),
E=1/(5:44))
> cor(fakeData)
  A B C D E
A 1.000 0.9782320 0.9481293 0.9215071 0.8988962
B 0.9782320 1.000 0.9932037 0.9811287 0.9684658
C 0.9481293 0.9932037 1.000 0.9969157 0.9906838
D 0.9215071 0.9811287 0.9969157 1.000 0.9983014
E 0.8988962 0.9684658 0.9906838 0.9983014 1.000
> psych::omegaSem(fakeData)
Loading required namespace: lavaan
Loading required namespace: GPArotation
In factor.stats, I could not find the RMSEA upper bound . Sorry about that
Error in parse(text = x, keep.source = FALSE) :
  :2:0: unexpected end of input
1: ~
   ^
In addition: Warning message:
In cov2cor(t(w) %*% r %*% w) :
  diag(.) had 0 or NA entries; non-finite result is doubtful
> psych::omega(fakeData)$model$lavaan
In factor.stats, I could not find the RMSEA upper bound . Sorry about that
[1] g =~ +A+B+C+D+E   F1=~  + B + C + D + E F2=~  + A
[4] F3=~
Warning message:
In cov2cor(t(w) %*% r %*% w) :
  diag(.) had 0 or NA entries; non-finite result is doubtful

You can get a result if you use nfactors=n where n is the number of the
good F entries in psych::omega()$model$lavaan:
> psych::omegaSem(fakeData, nfactors=2)
...

Measures of factor score adequacy
   gF1*  F2*
Correlation of scores with factors 11.35  12.4284.45
Multiple R square of scores with factors  128.93 154.32  7131.98
Minimum correlation of factor score estimates 256.86 307.64 14262.96
...
Does that work with your data?

This is a problem that the maintainer of psych,
>   maintainer("psych")
[1] "William Revelle "
would like to know about.






Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Aug 29, 2019 at 9:03 AM Danilo Esteban Rodriguez Zapata via R-help <
r-help@r-project.org> wrote:

> This is a problem related to my last question referred to the omegaSem()
> function in the psych package (that is already solved because I realized
> that I was missing a variable assignment and because of that I had an
> 'object not found' error:
>
>
> https://stackoverflow.com/questions/57661750/one-of-the-omegasem-function-arguments-is-an-object-not-found
>
> I was trying to use that function following the guide to find McDonald's
> hierarchical Omega by Dr William Revelle:
>
> http://personality-project.org/r/psych/HowTo/omega.pdf
>
> So now, with the variable error corrected, I'm having a different error
> that does not occur when I use the same function with the example database
> (Thurstone) provided in the tutorial that comes with the psych package. I
> mean, I'm able to use the function succesfully using the Thurstone data
> (with no other action, I have the expected result) but the function doesn't
> work when I use my own data.
>
> I searched over other posted questions, and the actions that they perform
> are not even similar to what I'm trying to do. I have almost two weeks
> using R, so I'm not able to identify yet how can I extrapolate the
> solutions for that error message to my procedure (because it seems to be
> frequent), although I have basic code knowledge. However related questions
> give no anwer by now.
>
> Additionally, I decided to look over more documentation about the package,
> and when I was testing other functions, I was able to use the omegaSem()
> function with another example database, BUT after and only after I did the
> schmid transformation. So with that, I discovered that when I tried to use
> the omegaSem() function before the schmid tranformation I had the same
> error message, but not after that tranformation with this second example
> database.
>
> This make sense with the actual procedure of the omegaSem() procedure, but
> I'm suposing that it must be done completely and automatically by the
> omegaSem() function as it is explained in the guide and I have understood
> until now, as it follows:
>
> 1. omegaSem() applies factor analysis
> 2. omegaSem() rotate factors obliquely
> 3. omegaSem() transform data with Schmid Leiman (schmid)
>
> ---necessary steps to print output---
>
> 4. omegaSem() print McDonald's hierarchical Omega
>
> So here, another questions appears:  - Why the omegaSem() function works
> with the Thurstone database without any other action and only works for the
> second example database after performing the schmid transformation? -  Why
> with other databases I dont have the same output applying the omegaSem()
> function directly? - How is this 

Re: [R] Creating data using multiple for loops

2019-08-19 Thread William Dunlap via R-help
do.call(paste0,expand.grid(0:1000, 1:12, 1:30)) takes care of storing all
the values, but note that paste() doesn't put leading zeroes in front of
small numbers so this maps lots of  ssn/month/day combos to the the same
id.  sprintf() can take care of that:
id <- with(expand.grid(ssn=0:1000, month=1:12, day=1:30),
sprintf("%04d%02d%02d", ssn, month, day))

You probably should define a function to map vectors of ssn, month,  and
day to a vector of ids (it can also check for inappropriate inputs), check
that it works, and use it instead of repeating the sprintf() or paste0()
code.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sun, Aug 18, 2019 at 12:18 PM Bert Gunter  wrote:

> id <- do.call(paste0,expand.grid(0:9, 1:3, 1:5))
>
> Comment: If you use R much, you'll do much better using R language
> constructs than trying to apply those from other languages (Java perhaps?).
> I realize this can be difficult, especially if you are experienced in the
> another language (or languages), but it's worth the effort.
>
>
> 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 Sun, Aug 18, 2019 at 11:58 AM  wrote:
>
> > I would like to create pseudo identification numbers in the format of
> last
> > four of a social security number ( to ), month of birth (01 to
> 12),
> > and day of birth (01-28). The IDs can be character.
> >
> > I have gotten this far:
> >
> > for (ssn in 0:9){
> >  for (month in 1:3){
> >   for (day in 1:5){
> >   }
> >   id <-paste(ssn, month, day, sep="")
> > }
> > }
> >
> > limiting each value above for demonstration purposes. I cannot figure out
> > how to store the created IDs. I know I have to create a container, but I
> > don't know, among other things, how to index the container.  Any help is
> > appreciated. TIA
> >
> > -Greg
> >
> > [[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] gmp coredump - where to report?

2019-08-17 Thread William Dunlap via R-help
  I has trying to convert some raw values into a big number with the
library gmp.
However the library makes R crash. Two questions:
1. Should I report the problem and if yes, where can I report the problem?

You can report the problem by calling bug.report(package="gmp") and filling
in the details.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Aug 16, 2019 at 4:10 PM Martin Møller Skarbiniks Pedersen <
traxpla...@gmail.com> wrote:

> Hi,
>
>   I has trying to convert some raw values into a big number with the
> library gmp.
> However the library makes R crash. Two questions:
>
> 1. Should I report the problem and if yes, where can I report the problem?
> 2. Is the source code for the R version of GMP somewhere on eg. github, so
> I can
> post an issue?
>
> Regards
> Martin
>
> Here is the code that generate the core-dump:
>
> $ head  -3 ~/R/x86_64-pc-linux-gnu-library/3.6/gmp/DESCRIPTION
> Package: gmp
> Version: 0.5-13.5
> Date: 2019-02-21
>
> $ R --version | head -3
> R version 3.6.1 (2019-07-05) -- "Action of the Toes"
> Copyright (C) 2019 The R Foundation for Statistical Computing
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> $ R --vanilla
>
> > library(gmp)
> > as.bigz(charToRaw("a"))
>
>  *** caught segfault ***
> address 0x560e78e1dd4c, cause 'memory not mapped'
>
> [[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] separate and gather functions

2019-08-12 Thread William Dunlap via R-help
This one uses only core R functions.  Does that count toward "elegance"?

> # your data, I assume, in a form one can copy and paste into R
> d <- data.frame(stringsAsFactors = FALSE,
Col1 = c("Agency A", "Agency B", "Agency C"),
Col2 = c("Function1, Function2, Function3, Function4",
"Function2, Function4", "Function1, Function3, Function4"))
> # split Col2 by comma following by any number of spaces
> tmp <- strsplit(d$Col2, split=", *")
> data.frame(Col1 = rep(d$Col1, lengths(tmp)), Col2 = unlist(tmp),
stringsAsFactors=FALSE)
  Col1  Col2
1 Agency A Function1
2 Agency A Function2
3 Agency A Function3
4 Agency A Function4
5 Agency B Function2
6 Agency B Function4
7 Agency C Function1
8 Agency C Function3
9 Agency C Function4

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Aug 12, 2019 at 4:23 PM  wrote:

> R-Help Forum
>
>
>
> I have a data set from which I have extracted two columns Column 1 is a
> listing of Federal agencies and Column 2 lists functions like this
>
>
>
> Col1   Col2
>
> Agency A Function1, Function2, Function3, Function4
>
> Agency B  Function2, Function4
>
> Agency C  Function1, Function3, Function4
>
>
>
> What I need is a long list like this
>
>
>
> Col1   Col2
>
> Agency A Function1
>
> Agency A Function2
>
> Agency 4  Function3 etc
>
>
>
> Is there a more elegant /efficient way other than what I did which was to
> separate Col2 into separate columns and then gather the data back up
>
>
>
> myDat3 <- separate(data= myDat2, col = type, into = c("x1", "x2", "x3",
> "x4", "x5"), sep = ",")
>
> myDat4 <- gather(data=myDat3, key="type", value = "Value",
> "x1","x2","x3","x4","x5", na.rm = TRUE)
>
>
>
> while it works, looking for a more elegant solution, if there is one
>
>
>
> Jeff
>
>
> [[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] Loading large tar.gz XenaHub Data into R

2019-08-01 Thread William Dunlap via R-help
By the way, instead of saying only that there were warnings, it would be
nice to show some of them.  E.g.,
> z <- readLines("
https://tcga.xenahubs.net/download/TCGA.GBMLGG.sampleMap/HumanMethylation450.gz
")
[ Hit control-C or Esc to interrupt, or wait a long time ]
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In readLines("
https://tcga.xenahubs.net/download/TCGA.GBMLGG.sampleMap/HumanMethylation450.gz;)
:
  line 1 appears to contain an embedded nul
2: In readLines("
https://tcga.xenahubs.net/download/TCGA.GBMLGG.sampleMap/HumanMethylation450.gz;)
:
  line 4 appears to contain an embedded nul
3: In readLines("
https://tcga.xenahubs.net/download/TCGA.GBMLGG.sampleMap/HumanMethylation450.gz;)
:
  line 7 appears to contain an embedded nul

Burt's guess looks right, as the following gives 10 long lines of
reasonable-looking data.  Remove the 'n=10' to get all of it.

z <- readLines(gzcon(url("
https://tcga.xenahubs.net/download/TCGA.GBMLGG.sampleMap/HumanMethylation450.gz;)),
n=10)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Aug 1, 2019 at 3:37 PM Bert Gunter  wrote:

> These are gzipped files, I assume. So see ?gzfile and associated info
> for how to open a gzip connection and read from it. You may also
> prefer to search (e.g. at rseek.org) on "read a gzipped file" or
> similar for possible alternatives.
>
> Of course, if they're not gzipped files, then ignore the above. If
> they are, your current approach is hopeless.
>
>
> Cheers,
> Bert
>
> On Thu, Aug 1, 2019 at 3:13 PM Spencer Brackett
>  wrote:
> >
> > Good evening,
> >
> > I am attempting to load the following Xena dataset
> >
> https://tcga.xenahubs.net/download/TCGA.GBMLGG.sampleMap/HumanMethylation450.gz
> >
> > I am trying to unpack the dataset and read it into R as a table, but due
> to
> > the size of the file, I am having some trouble. The following are the
> > commands I have tried thus far.
> >
> > HumanMethylation450 <- fread("
> >
> https://tcga.xenahubs.net/download/TCGA.GBMLGG.sampleMap/HumanMethylation450.gz
> > ")
> >
> > readLines("
> >
> https://tcga.xenahubs.net/download/TCGA.GBMLGG.sampleMap/HumanMethylation450.gz
> > ")
> >
> >  ###These two above attempts failed with warning messages
> > from R###
> >
> > Methyl <-read.delim("
> >
> https://tcga.xenahubs.net/download/TCGA.GBMLGG.sampleMap/HumanMethylation450.gz
> > ")
> >
> >##This attempt is still processing, but has been doing so
> > for quite some time##
> >
> > Any ideas as to what else I could try?
> >
> > Best,
> >
> > Spencer
> >
> > [[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.
>

[[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] Printing vector

2019-07-22 Thread William Dunlap via R-help
By the way, the default print method has the argument 'na.print' that can
speciify how to print an NA value.  E.g.,

> print(c(1234/, NA, 1), na.print="n/a")
[1] 0.1234123   n/a 1.000
> print(c(1234/, NA, 1), na.print="")
[1] 0.1234123   1.000
> print(c(1234/, NA, 1))
[1] 0.1234123NA 1.000



Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jul 22, 2019 at 11:07 AM Steven  wrote:

> Thank you, Gentlemen. That serves my need. Bill's routine is great.
>
> Also, Rui: Is there a way to get rid of the filled "NA" and use space
> instead. Using fill = "" does not help either; it causes all numbers to be
> embraced with quotations. Finally, I have no idea why Rui's message did not
> reach me at all (not even in the junk mail box). But, obviously Bill had
> received it. Hmm.
>
> Steven Yen
> William Dunlap 於 2019/7/23 上午 12:33 寫道:
>
> The following mimics Fortran printing with format
> F..
>
> print1 <- function (x, perLine = 10, fWidth = 8, fPrecision = 2,
> fortranStars = TRUE)
> {
> format <- paste0("%", fWidth, ".", fPrecision, "f")
> oldWidth <- getOption("width")
> on.exit(options(width = oldWidth))
> options(width = perLine * fWidth)
> fx <- sprintf(format, x)
> if (fortranStars) {
> fx[nchar(fx) > fWidth] <- strrep("*", fWidth)
> }
> cat(fx, sep = "", fill = TRUE)
> invisible(x)
> }
>
> Compare
> > print1((-1.7)^(1:24))
>-1.702.89   -4.918.35  -14.20   24.14  -41.03   69.76 -118.59
>  201.60
>  -342.72  582.62 -990.46 1683.78-2862.42
> 4866.12-8272.4014063.0840642.31
> 
> with the output from the Fortran
> % cat a.f
>   double precision x(24);
>   integer i
>   do 10 i=1,24
> x(i) = (-1.7d0) ** i
>  10   continue
>   write(6, "(10f8.2)") x
>   stop
>   end
> % gfortran a.f
> % ./a.out
>-1.702.89   -4.918.35  -14.20   24.14  -41.03   69.76 -118.59
>  201.60
>  -342.72  582.62 -990.46 1683.78-2862.42
> 4866.12-8272.4014063.0840642.31
> 
>
>
> Compare
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Mon, Jul 22, 2019 at 12:19 AM Rui Barradas 
> wrote:
>
>> Simpler, no loops:
>>
>>
>> print0b <- function(x, len = 10, digits = 2, fill = ""){
>>n <- length(x)
>>x <- round(x, digits = digits)
>>m <- n %/% len
>>remainder <- n %% len
>>A <- matrix(x[seq_len(len*m)], ncol = len)
>>if(remainder > 0){
>>  A <- rbind(A, c(x[(len*m + 1):n], rep(fill, len*(m + 1) - n)))
>>}
>>A
>> }
>>
>>
>> Hope this helps,
>>
>> Rui Barradas
>>
>> Às 07:47 de 22/07/19, Rui Barradas escreveu:
>> > Hello,
>> >
>> > Maybe something like the following is what you want.
>> > I have added an extra argument 'fill' to allow to choose what to print
>> > in the end. It's default value is "" making the entire matrix elements
>> > characters but it can be NA or 0.
>> >
>> > print0 <- function(x, len = 10, digits = 2, fill = ""){
>> >n <- length(x)
>> >x <- round(x, digits = digits)
>> >passes <- n %/% len
>> >remainder <- n %% len
>> >A <- matrix(fill, nrow = passes + (remainder > 0), ncol = len)
>> >for(i in seq_len(passes)){
>> >  A[i, ] <- x[(len*(i - 1) + 1):(len*i)]
>> >}
>> >A[nrow(A), 1:remainder] <- x[(len*passes + 1):n]
>> >A
>> > }
>> >
>> > print0(rnorm(23), 10)
>> > print0(rnorm(23), 10, fill = 0)
>> >
>> >
>> > Hope this helps,
>> >
>> > Rui Barradas
>> >
>> > Às 21:34 de 20/07/19, Steven escreveu:
>> >> Dear All:
>> >>
>> >> Below is what I meant. Procedure print0 allows me to print a vector of
>> >> length 53 in four rows of 10 plus 1 row of 3 (Ido not like the NA).
>> This
>> >> is silly. I am hoping that there is a candid way to print the matrix.
>> >> Thank you.
>> >>
>> >> Steven Yen
>> >>
>> >> ===
>> >> n<-53; x<-runif(n); # x<-round(x,2)
>> >>
>> >> print0<-function(x,c=10,digits=2){
>> >> # **
>>

Re: [R] Printing vector

2019-07-22 Thread William Dunlap via R-help
The following mimics Fortran printing with format
F..

print1 <- function (x, perLine = 10, fWidth = 8, fPrecision = 2,
fortranStars = TRUE)
{
format <- paste0("%", fWidth, ".", fPrecision, "f")
oldWidth <- getOption("width")
on.exit(options(width = oldWidth))
options(width = perLine * fWidth)
fx <- sprintf(format, x)
if (fortranStars) {
fx[nchar(fx) > fWidth] <- strrep("*", fWidth)
}
cat(fx, sep = "", fill = TRUE)
invisible(x)
}

Compare
> print1((-1.7)^(1:24))
   -1.702.89   -4.918.35  -14.20   24.14  -41.03   69.76 -118.59
 201.60
 -342.72  582.62 -990.46 1683.78-2862.42
4866.12-8272.4014063.0840642.31

with the output from the Fortran
% cat a.f
  double precision x(24);
  integer i
  do 10 i=1,24
x(i) = (-1.7d0) ** i
 10   continue
  write(6, "(10f8.2)") x
  stop
  end
% gfortran a.f
% ./a.out
   -1.702.89   -4.918.35  -14.20   24.14  -41.03   69.76 -118.59
 201.60
 -342.72  582.62 -990.46 1683.78-2862.42
4866.12-8272.4014063.0840642.31



Compare
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jul 22, 2019 at 12:19 AM Rui Barradas  wrote:

> Simpler, no loops:
>
>
> print0b <- function(x, len = 10, digits = 2, fill = ""){
>n <- length(x)
>x <- round(x, digits = digits)
>m <- n %/% len
>remainder <- n %% len
>A <- matrix(x[seq_len(len*m)], ncol = len)
>if(remainder > 0){
>  A <- rbind(A, c(x[(len*m + 1):n], rep(fill, len*(m + 1) - n)))
>}
>A
> }
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 07:47 de 22/07/19, Rui Barradas escreveu:
> > Hello,
> >
> > Maybe something like the following is what you want.
> > I have added an extra argument 'fill' to allow to choose what to print
> > in the end. It's default value is "" making the entire matrix elements
> > characters but it can be NA or 0.
> >
> > print0 <- function(x, len = 10, digits = 2, fill = ""){
> >n <- length(x)
> >x <- round(x, digits = digits)
> >passes <- n %/% len
> >remainder <- n %% len
> >A <- matrix(fill, nrow = passes + (remainder > 0), ncol = len)
> >for(i in seq_len(passes)){
> >  A[i, ] <- x[(len*(i - 1) + 1):(len*i)]
> >}
> >A[nrow(A), 1:remainder] <- x[(len*passes + 1):n]
> >A
> > }
> >
> > print0(rnorm(23), 10)
> > print0(rnorm(23), 10, fill = 0)
> >
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > Às 21:34 de 20/07/19, Steven escreveu:
> >> Dear All:
> >>
> >> Below is what I meant. Procedure print0 allows me to print a vector of
> >> length 53 in four rows of 10 plus 1 row of 3 (Ido not like the NA). This
> >> is silly. I am hoping that there is a candid way to print the matrix.
> >> Thank you.
> >>
> >> Steven Yen
> >>
> >> ===
> >> n<-53; x<-runif(n); # x<-round(x,2)
> >>
> >> print0<-function(x,c=10,digits=2){
> >> # **
> >> # Print vector in rows of a specified length
> >> # **
> >> n<-length(x)
> >> r<-n/c; if(n%%c>0) r<-as.integer(r)+1
> >> y<-rep(NA,r*c)
> >> y[1:n]<-x
> >> y<-matrix(y,r,c,byrow=T)
> >> y<-round(y,digits=digits)
> >> y
> >> }
> >>
> >> print0(x,c=10,digits=3)
> >>
> >> # result
> >> # [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9] [,10]
> >> # [1,] 0.576 0.291 0.600 0.515 0.135 0.335 0.296 0.911 0.454 0.696
> >> # [2,] 0.699 0.728 0.442 0.469 0.996 0.539 0.772 0.768 0.652 0.882
> >> # [3,] 0.614 0.228 0.748 0.071 0.788 0.428 0.885 0.722 0.432 0.881
> >> # [4,] 0.422 0.148 0.459 0.870 0.044 0.421 0.282 0.337 0.751 0.579
> >> # [5,] 0.468 0.659 0.446 0.199 0.388 0.576 0.829 0.186 0.823 0.960
> >> # [6,] 0.880 0.944 0.709NANANANANA NANA
> >>
> >> Steven 於 2019/7/20 下午 02:00 寫道:
> >>>
> >>> Is there a convenient way to print a vector into rows of a specified
> >>> column length? What I need is to print in the old FORTRAN format, viz.,
> >>>
> >>> format(10F8.2)
> >>>
> >>> which would print, for instance, a vector of 25 into two rows of 10
> >>> plus an incomplete row of 5. I managed to write a procedure for that
> >>> task, as shown below (except that I prefer simply blanks rather than
> >>> the NA). I am too embarrassed to even show the procedure. In short, I
> >>> like to print in the above FORTRAN format. Thank you.
> >>>
> >>> 
> >>>
> >>> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0.66 0.26 0.82
> >>> 0.73 0.13 0.05 0.56 0.67 0.74 0.87 [2,] 0.91 0.25 0.40 0.39 0.50 0.89
> >>> 0.07 0.84 0.14 0.75 [3,] 0.38 0.08 0.86 0.97 0.56 NA NA NA NA NA
> >>
> >> [[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, 

Re: [R] R 3.6.1 and apcluster package

2019-07-18 Thread William Dunlap via R-help
If you use version=3, ascii=TRUE and look at the file made up to the point
of the error, you can see a quasi-infinite repeat of a block of 165 numbers
(after a deferred string called "base"?).  Looks like inappropriate
recursion.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Jul 18, 2019 at 7:38 AM William Dunlap  wrote:

> Note that you can reproduce this in R-3.5.1 if you specify serialization
> version 3 (which became the default in 3.6.0).
>
> > save(apresX, file="351-2.RData", version=2)
> > save(apresX, file="351-2.RData", version=3)
> Error: C stack usage  7969184 is too close to the limit
> > version$version.string
> [1] "R version 3.5.1 (2018-07-02)"
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Thu, Jul 18, 2019 at 12:46 AM Jan Galkowski 
> wrote:
>
>> > # Test for saving. Jan Galkowski, 17th July 2019.
>> > # produceProtectionFault.R
>> >
>> > library(apcluster)
>> > cl1 <- cbind(rnorm(100, 0.2, 0.05), rnorm(100, 0.8, 0.06))
>> > cl2 <- cbind(rnorm(50, 0.7, 0.08), rnorm(50, 0.3, 0.05))
>> > x <- rbind(cl1, cl2)
>> >
>> > ## compute similarity matrix and run affinity propagation
>> > ## (p defaults to median of similarity)
>> > simil<- negDistMat(x, r=2)
>> > apres <- apcluster(s=simil, details=TRUE)
>> > apresX<- aggExCluster(s=simil, x=apres)
>> >
>> > show(apres)
>> > show(apresX)
>> >
>> > saveRDS(object=apresX, file="foo.rds", compress=TRUE)
>> >
>> > #save(apresX, file="bar.data", compress=TRUE)
>> >
>> > #save.image("crazy.RData")
>>
>> The example is from the apcluster documentation. Leaving any one of the
>> "save"s uncommented produces said fault.
>>
>>  - Jan
>>
>> On Wed, Jul 17, 2019, at 08:18, Jeff Newmiller wrote:
>> > It would never make sense for such messages to reflect normal and
>> expected operation, so hypothesizing about intentionally changing stack
>> behavior doesn't make sense.
>> >
>> > The default format for saveRDS changed in 3.6.0. There may be bugs
>> associated with that, but rolling back to 3.6.0 would just trade bugs.
>> >
>> > https://cran.r-project.org/doc/manuals/r-devel/NEWS.html
>> >
>> > On July 16, 2019 8:56:28 PM CDT, Jan Galkowski <
>> bayesianlogi...@gmail.com> wrote:
>> > >Did something seriously change in R 3.6.1 at least for Windows in terms
>> > >of stack impacts?
>> > >
>> > >I'm encountering many problems with the 00UNLOCK, needing to disable
>> > >locking during installations.
>> > >
>> > >And I'm encountering
>> > >
>> > >> Error: C stack usage 63737888 is too close to the limit
>> > >
>> > >for cases I did not before, even when all I'm doing is serializing an
>> > >object to be saved with *saveRDS* or even *save.image(.)*.
>> > >
>> > >Yes, I know, I did not append a minimally complete example. Just wanted
>> > >to see if it was just me, or if anyone else was seeing this.
>> > >
>> > >It's on Windows 7 HE and I've run *R* here for years.
>> > >
>> > >My inclination is to drop back to 3.6.0 if it is just me or if no one
>> > >knows about this problem.
>> > >
>> > >Thanks,
>> > >
>> > > - Jan Galkowski.
>> > >
>> > >
>> > > [[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.
>> >
>>
>> --
>> Jan Galkowski (o°)
>>
>> 607.239.1834 [mobile]
>> 607.239.1834 [home]
>>
>> bayesianlogi...@gmail.com
>> http://667-per-cm.net
>>
>> member,
>>
>> ... American Statistical Association
>> ... International Society for Bayesian Analysis
>> ... Ecological Society of America
>> ... International Association of Survey Statisticians
>> ... American Association for the Advancement of Science
>> ... TeX Users Group
>>
>> (pronouns: *he, him, his*)
>>
>> *Keep your energy local*. --John Farrell, *ILSR <http://ilsr.org/>*
>>
>>
>> [[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] R 3.6.1 and apcluster package

2019-07-18 Thread William Dunlap via R-help
Note that you can reproduce this in R-3.5.1 if you specify serialization
version 3 (which became the default in 3.6.0).

> save(apresX, file="351-2.RData", version=2)
> save(apresX, file="351-2.RData", version=3)
Error: C stack usage  7969184 is too close to the limit
> version$version.string
[1] "R version 3.5.1 (2018-07-02)"

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Jul 18, 2019 at 12:46 AM Jan Galkowski 
wrote:

> > # Test for saving. Jan Galkowski, 17th July 2019.
> > # produceProtectionFault.R
> >
> > library(apcluster)
> > cl1 <- cbind(rnorm(100, 0.2, 0.05), rnorm(100, 0.8, 0.06))
> > cl2 <- cbind(rnorm(50, 0.7, 0.08), rnorm(50, 0.3, 0.05))
> > x <- rbind(cl1, cl2)
> >
> > ## compute similarity matrix and run affinity propagation
> > ## (p defaults to median of similarity)
> > simil<- negDistMat(x, r=2)
> > apres <- apcluster(s=simil, details=TRUE)
> > apresX<- aggExCluster(s=simil, x=apres)
> >
> > show(apres)
> > show(apresX)
> >
> > saveRDS(object=apresX, file="foo.rds", compress=TRUE)
> >
> > #save(apresX, file="bar.data", compress=TRUE)
> >
> > #save.image("crazy.RData")
>
> The example is from the apcluster documentation. Leaving any one of the
> "save"s uncommented produces said fault.
>
>  - Jan
>
> On Wed, Jul 17, 2019, at 08:18, Jeff Newmiller wrote:
> > It would never make sense for such messages to reflect normal and
> expected operation, so hypothesizing about intentionally changing stack
> behavior doesn't make sense.
> >
> > The default format for saveRDS changed in 3.6.0. There may be bugs
> associated with that, but rolling back to 3.6.0 would just trade bugs.
> >
> > https://cran.r-project.org/doc/manuals/r-devel/NEWS.html
> >
> > On July 16, 2019 8:56:28 PM CDT, Jan Galkowski <
> bayesianlogi...@gmail.com> wrote:
> > >Did something seriously change in R 3.6.1 at least for Windows in terms
> > >of stack impacts?
> > >
> > >I'm encountering many problems with the 00UNLOCK, needing to disable
> > >locking during installations.
> > >
> > >And I'm encountering
> > >
> > >> Error: C stack usage 63737888 is too close to the limit
> > >
> > >for cases I did not before, even when all I'm doing is serializing an
> > >object to be saved with *saveRDS* or even *save.image(.)*.
> > >
> > >Yes, I know, I did not append a minimally complete example. Just wanted
> > >to see if it was just me, or if anyone else was seeing this.
> > >
> > >It's on Windows 7 HE and I've run *R* here for years.
> > >
> > >My inclination is to drop back to 3.6.0 if it is just me or if no one
> > >knows about this problem.
> > >
> > >Thanks,
> > >
> > > - Jan Galkowski.
> > >
> > >
> > > [[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.
> >
>
> --
> Jan Galkowski (o°)
>
> 607.239.1834 [mobile]
> 607.239.1834 [home]
>
> bayesianlogi...@gmail.com
> http://667-per-cm.net
>
> member,
>
> ... American Statistical Association
> ... International Society for Bayesian Analysis
> ... Ecological Society of America
> ... International Association of Survey Statisticians
> ... American Association for the Advancement of Science
> ... TeX Users Group
>
> (pronouns: *he, him, his*)
>
> *Keep your energy local*. --John Farrell, *ILSR *
>
>
> [[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] Read Unicode text (*.txt)

2019-07-02 Thread William Dunlap via R-help
Try changing encoding="UTF-16" to fileEncoding="UTF-16".

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jul 1, 2019 at 9:30 PM javad bayat  wrote:

> Dear all;
> I use your suggestion but I gave the same warning messages. I changed the
> file name (Data.csv).
> "
> d4<-read.csv("./Data.csv",sep=";",header=TRUE,encoding="UTF-16")
>  Warning messages:
>  1: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
>line 1 appears to contain embedded nulls
>   2: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
>   line 2 appears to contain embedded nulls
>   3: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
>   line 3 appears to contain embedded nulls
>   4: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
>line 4 appears to contain embedded nulls
>   5: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
> line 5 appears to contain embedded nulls
>   6: In read.table(file = file, header = header, sep = sep, quote =
> quote,  :
>line 1 appears to contain embedded nulls
>   7: In scan(file = file, what = what, sep = sep, quote = quote,
> dec = dec,  :
>  embedded nul(s) found in input
> "
>
> I opened the Data in notepad. This is the head of Data.csv. The columns
> have been separated by semicolons.
> "
> "INLET Time";"INLET ValueY";"TRATED WATER TANK Time";"TRATED WATER TANK
> ValueY"
> 10/28/2018;550.057861328125;10/28/2018;487.812530517578
> 10/28/2018 12:00:01 ق.ظ;550.057861328125;10/28/2018 12:00:01
> ق.ظ;487.812530517578
> 10/28/2018 12:00:02 ق.ظ;550.057861328125;10/28/2018 12:00:02
> ق.ظ;487.812530517578
> 10/28/2018 12:00:03 ق.ظ;550.057861328125;10/28/2018 12:00:03
> ق.ظ;487.812530517578
> 10/28/2018 12:00:04 ق.ظ;550.057861328125;10/28/2018 12:00:04
> ق.ظ;487.812530517578
> .
> .
> .
> "
> Thanks.
>
>
>
> On Tue, Jul 2, 2019 at 6:14 AM Jeff Newmiller 
> wrote:
>
> > Don't be so US-centric, Abby... how do you know that javad's version of
> > Excel doesn't default to using semicolons?
> >
> > ?read.csv2
> >
> > On July 1, 2019 6:06:32 PM PDT, Abby Spurdle 
> wrote:
> > >> I am trying to read an excel CSV file (1.csv). When I read it as csv
> > >file
> > >> in R, the R shows me the exact number of row. But it puts all columns
> > >in
> > >> one column, while I have 3 or 4 columns in the data frame.
> > >> d4 = read.table("./4.csv",sep=";",header=TRUE)
> > >
> > >Firstly, I recommend against naming your file "1.csv".
> > >(Start with a letter not a number).
> > >
> > >Secondly, a CSV file should be separated by commas not semicolons.
> > >You can specify sep=",", however, it's probably easier to use the
> > >read.csv() function.
> > >
> > >Note that you should be able to open your file in a text editor to see
> > >the
> > >separators.
> > >
> > >> I dont know why in the "save as type" box Unicode text (*.txt)
> > >
> > >Other posters have suggested that you need to specify the encoding.
> > >Assuming that you create your CSV file correctly in Excel, I doubt that
> > >this is necessary, but I could be wrong...
> > >
> > >Your comment suggests that you have saved your document as "Unicode
> > >text".
> > >You need to tell Excel to save the file as a CSV file.
> > >(There should be a list of save options).
> > >
> > >Simply typing a file name with a .csv file extension is unlikely to
> > >produce
> > >the desired result.
> > >
> > >   [[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.
> >
>
>
> --
> Best Regards
> Javad Bayat
> M.Sc. Environment Engineering
> Alternative Mail: bayat...@yahoo.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.
>

[[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] Read Unicode text (*.txt)

2019-07-01 Thread William Dunlap via R-help
If I recall correctly, Excel's 'Unicode' used to mean "UTF-16", which R's
scan() did not recognize without a hint.  The relevant argument is
fileEncoding, not encoding.  UTF-16 files generally have lots of null bytes
and UTF-8 files have no null bytes and if you try to read UTF-16 as UTF-8
you get the embedded-null warning.

I don't have Excel installed, but the following example is from R-3.5.2 on
a Linux box.

> f8 <- file(tf8 <- tempfile(), open="w", encoding="UTF-8")
> cat("\u0416;zh\n", file=f8); close(f8)
> readBin(tf8, what="raw", n=file.size(tf8))
[1] d0 96 3b 7a 68 0a
>
> f16 <- file(tf16 <- tempfile(), open="w", encoding="UTF-16")
> cat("\u0416;zh\n", file=f16); close(f16)
> readBin(tf16, what="raw", n=file.size(tf16))
 [1] ff fe 16 04 3b 00 7a 00 68 00 0a 00
>
> read.csv(tf8, sep=";", header=FALSE)
  V1 V2
1  Ж zh
> read.csv(tf16, sep=";", header=FALSE)
Error in type.convert.default(data[[i]], as.is = as.is[i], dec = dec,  :
  invalid multibyte string at ''
In addition: Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 1 appears to contain embedded nulls
2: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 2 appears to contain embedded nulls
3: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on
'/tmp/RtmpzfG6eG/file40e53389f40e'
> read.csv(tf16, sep=";", header=FALSE, fileEncoding="UTF-16")
  V1 V2
1  Ж zh
.
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jul 1, 2019 at 8:12 PM Abby Spurdle  wrote:

> > Don't be so US-centric, Abby... how do you know that javad's version of
> Excel doesn't default to using semicolons?
>
> I don't.
>
> However, Comma-Separated Values (CSV) are, comma separated, by definition.
> So, if the files use semicolons, then...
>
> Also, the use of the wrong sep="my.delim" argument is the most likely cause
> of single column output.
>
> However, you're right, I don't really know, I'm just guessing...
>
> [[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] Read Unicode text (*.txt)

2019-07-01 Thread William Dunlap via R-help
Should that  encoding="UTF-8"  be  encoding="UTF-16"?

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jul 1, 2019 at 2:45 PM Jim Lemon  wrote:

> Hi Javad,
> Unicode characters do have embedded nulls. Try this:
>
> d4<-read.table("./4.csv",sep=";",header=TRUE,encoding="UTF-8")
>
> Jim
>
> On Tue, Jul 2, 2019 at 3:47 AM javad bayat  wrote:
> >
> > Dear R users;
> > I am trying to read an excel CSV file (1.csv). When I read it as csv file
> > in R, the R shows me the exact number of row. But it puts all columns in
> > one column, while I have 3 or 4 columns in the data frame.
> > "
> > d4 = read.table("./4.csv",sep=";",header=TRUE)
> >  Warning messages:
> >  1: In read.table("./4.csv", sep = ";", header = TRUE) :
> >   line 1 appears to contain embedded nulls
> >  2: In read.table("./4.csv", sep = ";", header = TRUE) :
> >  line 2 appears to contain embedded nulls
> >  3: In read.table("./4.csv", sep = ";", header = TRUE) :
> >  line 3 appears to contain embedded nulls
> >  4: In read.table("./4.csv", sep = ";", header = TRUE) :
> >  line 4 appears to contain embedded nulls
> >  5: In read.table("./4.csv", sep = ";", header = TRUE) :
> > line 5 appears to contain embedded nulls
> >  6: In read.table("./4.csv", sep = ";", header = TRUE) :
> > line 1 appears to contain embedded nulls
> >  7: In scan(file = file, what = what, sep = sep, quote = quote, dec =
> > dec,  :
> >embedded nul(s) found in input
> > > attach(d4)
> > > dim(d4)
> > [1] 1814394   1
> > "
> > I opened the csv file in excel and I tried to make a new csv (delimited)
> > file. I dont know why in the "save as type" box Unicode text (*.txt) is
> > written. Why the format is txt while the file extension is .CSV?
> > Please help me to read this format correctly.
> > Many thanks.
> >
> >
> >
> > --
> > Best Regards
> > Javad Bayat
> > M.Sc. Environment Engineering
> > Alternative Mail: bayat...@yahoo.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.
>
> __
> 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] problem in saving the history file '~/.Rhistory'

2019-06-26 Thread William Dunlap via R-help
Did you (or a startup script) set the environment variable R_HISTORY to be
'~/somefile'?  R does not expand the tilde in this case so you need to let
the shell do it.  Perhaps ~ doesn't expand for the root user.  (IMO, it is
crazy to run R, or almost any other program, as root.)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Jun 26, 2019 at 7:11 AM lejeczek via R-help 
wrote:

> hi guys,
>
> I'm on Centos 7.6 with R 3.6 and I see this:
>
> >
> Save workspace image? [y/n/c]: y
> Warning message:
> problem in saving the history file '~/.Rhistory'
>
> from strace:
>
> rt_sigaction(SIGWINCH, {SIG_DFL, [], SA_RESTORER, 0x7fb9dd34b5d0},
> {0x7fb9dc383820, [], SA_RESTORER|SA_RESTART, 0x7fb9dd34b5d0}, 8) = 0
> rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> ioctl(1, TCXONC, TCOON) = 0
> open("~/.Rhistory", O_WRONLY|O_CREAT|O_TRUNC, 0600) = -1 ENOENT (No such
> file or directory)
> brk(NULL)   = 0x43da000
> brk(0x43fe000)  = 0x43fe000
> rt_sigaction(SIGINT, {SIG_IGN, [], SA_RESTORER, 0x7fb9dcfa2280},
> {0x7fb9dfd99ffb, [INT], SA_RESTORER|SA_RESTART, 0x7fb9dd34b5d0}, 8) = 0
> rt_sigaction(SIGQUIT, {SIG_IGN, [], SA_RESTORER, 0x7fb9dcfa2280},
> {SIG_DFL, [], SA_RESTORER, 0x7fb9dd34b5d0}, 8) = 0
> rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
> clone(child_stack=0, flags=CLONE_PARENT_SETTID|SIGCHLD,
> parent_tidptr=0x7ffd7d87e100) = 1367359
> wait4(1367359, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 1367359
> rt_sigaction(SIGINT, {0x7fb9dfd99ffb, [INT], SA_RESTORER|SA_RESTART,
> 0x7fb9dcfa2280}, NULL, 8) = 0
> rt_sigaction(SIGQUIT, {SIG_DFL, [], SA_RESTORER, 0x7fb9dcfa2280}, NULL,
> 8) = 0
> rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
> --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=1367359,
> si_uid=0, si_status=0, si_utime=0, si_stime=1} ---
> write(2, "Warning message:\n", 17)  = 17
> write(2, "problem in saving the history fi"..., 50) = 50
> exit_group(0)   = ?
> +++ exited with 0 +++
>
>
> This only with user "root", and the some root can touch the ~/.Rhistory
> just fine.
>
> Even this works:
>
> > system(command="touch ~/.Rhistory")
>
> Would have any suggestions, ideas on how to fix it?
>
> many thanks, L.
>
> __
> 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] Problem with reading file saved in directory

2019-06-21 Thread William Dunlap via R-help
Reading the file with row.names=1 meant to make rownames out of the first
column in the text file.  Duplicate row names are not accepted.  To
diagnose, read it with row.names=NULL and see what is in the first column
(e.g., use the table function on it).

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Jun 21, 2019 at 3:56 PM Spencer Brackett <
spbracket...@saintjosephhs.com> wrote:

> Good evening,
>
> I set up a working directory to read the indicated desktop file, but
> implementation of the read.file function produced the following error...
>
> >meth = read.table(file = "~/Vakul's GBM code/mapper.txt", sep  ="\t",
> header = T, row.names = 1)
> Error in read.table(file = "~/Vakul's GBM code/mapper.txt", sep = "\t",  :
> duplicate 'row.names' are not allowed
> In addition: Warning message:
> In scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  :
>   EOF within quoted string
>
> What does it mean by "duplicate row names are not allowed" ? is the file I
> am attempting to access somehow not compatible? Also, how do I address the
> second part of the warning referring to what was found "In scan" ?
>
> Best,
>
> Spencer
>
> [[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] Recovering former projects on R

2019-06-21 Thread William Dunlap via R-help
You should ask someone at RStudio about this, but *.Rproj files are not
something R itself knows about.  load() reads files made by save(), which
usually have the extension ".Rdata" or ".rda".

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Jun 21, 2019 at 1:43 PM Spencer Brackett <
spbracket...@saintjosephhs.com> wrote:

> Good evening,
>
>   I am revisiting a project I had saved to R studio and after working with
> it for a little, with loaded data and environments shown just as I left
> them when I stopped working on the project, my console and the tabs opened
> went blank. I believe I accidentally activated q() and quit the project. I
> tried to re-access the same file with all of the work I’ve done for this
> project saved onto it, and I got the following...
>
>
>  load("~/R/GBM P-EXP/GBM P-EXP.Rproj")
> Error in load("~/R/GBM P-EXP/GBM P-EXP.Rproj") :
>   bad restore file magic number (file may be corrupted) -- no data loaded
> In addition: Warning message:
> file ‘GBM P-EXP.Rproj’ has magic number 'Versi'
>   Use of save versions prior to 2 is deprecated
>
> Does this mean that I lost all of my previous work, or is there another way
> to recover all the coding and loaded environments that I had saved to this
> file?  For context, I also tried accessing the project through a desktop
> version of the file saved on my desktop through R Studio, but this also
> just generated a blank terminal with no loaded environments.
>
> Any advice would be greatly appreciated!
>
> Best,
>
> Spencer Brackett
>
> [[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] Help with another ggplot error

2019-06-13 Thread William Dunlap via R-help
> Hello I have created a function called autocorrelate.
>
> When I run it with ggplot I get this error:
> #Error in autocorrelate(., NetEditRev, lags = 0:nrow(.)) :   unused
argument (lags = 0:nrow(.))

This means that autocorrelate does not have an argument called lags.  E.g.
   > f <- function(x) x+1
   > f(y=10)
   Error in f(y = 10) : unused argument (y = 10)
It looks like your autocorrelate has an argument called 'Lags', not 'lags'.


Use traceback() after an error
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Jun 13, 2019 at 7:14 AM Bill Poling  wrote:

>
> #RStudio Version 1.2.1335
> sessionInfo()
> #R version 3.5.3 (2019-03-11)
> #Platform: x86_64-w64-mingw32/x64 (64-bit)
> #Running under: Windows >= 8 x64 (build 9200)
>
> Hello I have created a function called autocorrelate.
>
> When I run it with ggplot I get this error:
> #Error in autocorrelate(., NetEditRev, lags = 0:nrow(.)) :   unused
> argument (lags = 0:nrow(.))
>
> Using what I learned from Rui yesterday I have tried to track down the
> problem myself
>
> #-- ggplot ISSUE 2
> ---#
>
> #--#
> getAnywhere('lags')
>
> # A single object matching 'lags' was found
> # It was found in the following places
> # package:TTR
> # namespace:TTR
> # with value
>
> function (x, n = 1)
> {
>   x <- as.matrix(x)
>   if (is.null(colnames(x)))
> colnames(x) <- paste("V", 1:NCOL(x), sep = "")
>   out <- embed(x, n + 1)
>   if (n == 1)
> lag.names <- 1
>   else if (NCOL(x) == 1)
> lag.names <- 1:n
>   else lag.names <- rep(1:n, NCOL(x))
>   colnames(out) <- c(colnames(x), paste(colnames(x), sort(lag.names),
> sep = "."))
>   return(out)
> }
> 
> # 
>
> #Here are references I have perused but not sure they help, or at least I
> do not understand how they help me?
>
>
> https://stackoverflow.com/questions/32056718/annotate-ggplot-bar-chart-error-unused-arguments
> #https://stackoverflow.com/questions/24004974/sudden-unused-argument-error
> 
>
> find("lags")
> #"package:TTR"
>
> #Here are the Pkgs/libraries loaded, and I see TTR_0.23-4
> # I did not load this library so it must be coming in with another library?
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> other attached packages:
>  [1] plotly_4.9.0   tseries_0.10-46
> timeDate_3043.102  h2o_3.22.1.1   lime_0.4.1
>  [6] parsnip_0.0.2  sweep_0.2.1.1  forecast_8.7
>riem_0.1.1 timetk_0.1.1.1
> [11] tidyquant_0.5.6forcats_0.4.0  stringr_1.4.0
> dplyr_0.8.1purrr_0.3.2
> [16] readr_1.3.1tidyr_0.8.3tibble_2.1.1
>ggplot2_3.1.1  tidyverse_1.2.1
> [21] quantmod_0.4-14TTR_0.23-4
>  PerformanceAnalytics_1.5.2 xts_0.11-2 zoo_1.8-5
> [26] lubridate_1.7.4yardstick_0.0.3
>
> ?`TTR-package`
>
> These are the libraries I have loaded
>
> library(yardstick)
> library(tidyquant)
> library(timetk)
> library(riem)
> library(forecast)
> library(sweep)
> library(parsnip)
> library(lime)
> library(h2o)
> library(timeDate)
> library(tseries)
> library(ggplot2)
> library(tidyverse)
> library(lubridate)
> library(plotly)
>
> I tried changing lags to lags1 in the function but that did not help
>
> Here are the script and a data sample to assist anyone who might try to
> help me.
>
> Thank you for any advice.
>
> WHP
>
>
> #Create a function
>
> autocorrelate <- function(dftmp, value, Lags = 0.20) {
>
>   value_expr <- enquo(value)
>
>   acf_values <- dftmp %>%
> select(!! value_expr) %>%
> pull() %>%
> acf(lag.max = tail(lags, 1), plot = FALSE) %>%
> .$acf %>%
> .[,,1]
>
>   ret <- tibble(acf = acf_values) %>%
> rowid_to_column(var = "lag") %>%
> mutate(lag = lag - 1) %>%
> filter(lag %in% lags)
>
>   return(ret)
> }
>
> g2 <- as_tibble(dftmp) %>%
>   autocorrelate(NetEditRev,lags = 0:nrow(.)) %>%
>   ggplot(aes(lag,acf)) +
>   geom_point(alpha = 0.5, color = "#2c3e50") +
>   expand_limits(y = c(-1,1)) +
>   theme_tq() +
>   labs(title  = "Autocorrelation For Net Edit Revenue")
> #And I get --> Error in autocorrelate(., NetEditRev, lags = 0:nrow(.)) :
>  unused argument (lags = 0:nrow(.))
> #Notice in the error it looks like autocorrelate(., yet there is no ., in
> my script?
>
> ggplotly(g2)
>
>
>
> str(dftmp)
>
> 'data.frame':892 obs. of  10 variables:
>  $ Date2 : Date, format: "2017-01-01" "2017-01-02" "2017-01-03"
> "2017-01-04" ...
>  $ NetEditRev: num  -923 19222 -8397 37697 46075 ...
>  

Re: [R] reg expr that retains only bracketed text from strings

2019-06-12 Thread William Dunlap via R-help
strcapture() can help here.

> mystrings<-c("ABC","A(B)C","AB(C)")
> strcapture("^[^{]*(\\([^(]*\\)).*$", mystrings,
proto=data.frame(InParen=""))
  InParen
1
2 (B)
3 (C)

Classic regular expressions don't do so well with nested parentheses.
Perhaps a perl-style RE could do that.
> strcapture("^[^{]*(\\([^(]*\\)).*$", proto=data.frame(InParen=""),
x=c("()", "a(s(d)f)g"))
  InParen
1  ()
2   (d)f)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Jun 11, 2019 at 10:46 PM nevil amos  wrote:

> Hi
>
> I am trying to extract only the text contained in brackets from a vector of
> strings
> not all of the strings contain closed bracketed text, they should return an
> empty string or NA
>
> this is what I have at the moment
>
>
> mystrings<-c("ABC","A(B)C","AB(C)")
>
> substring(mystrings, regexpr("\\(|\\)", mystrings))
>
>
> #this returns the whole string  if there are no brackets.
> [1] "ABC"  "(B)C" "(C)"
>
>
> # my desired desired output:
> #[1]  ""  "(B)" "(C)"
>
> many thanks for any suggestions
> Nevil Amos
>
> [[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] [Rd] Open a file which name contains a tilde

2019-06-11 Thread William Dunlap via R-help
Note that R treats tildes in file names differently on Windows and Linux.
On Windows, it is only replaced if it it at the beginning of the line and
is followed by a forward or backward slash or end-of-line.  On Linux it is
replaced no matter where it is in the text and ~someUser will be replaced
by someUser's home directory (if 'someUser' is a user with a home
directory).

Hence, if you have a Windows machine that can look at the file system on
your Linux machine you can use file.rename on Windows to change the names.
My inclination would be to use a bash script on Linux to change the names,
but if you are not comfortable with bash try the Windows approach.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Jun 11, 2019 at 1:13 PM Frank Schwidom  wrote:

> Hi Gabriel,
>
> I actually want to make renames over thousands of files. But if I am not
> able to express the source filename of the rename operation I will not be
> able to get the work done. Besides the fact that there are issues I think
> that R is qualified for solving my problem by the method how it can handle
> long vectors of strings, booleans and also lists.
>
> Kind regards,
> Frank
>
> On 2019-06-11 09:49:17, Gabriel Becker wrote:
> >Hi Frank,
> >I'm hesitant to be "that guy", but in case no one else has brought
> this up
> >to you, having files with a tilde in their names (generally but
> especially
> >on a linux system, where ~ in file names has a very important special
> >meaning in some cases, as we know) strikes me as an exceptionally bad
> >practice anyway. In light of that, the solution with the smallest
> amount
> >of pain for you is almost surely to just... not do that. Your
> filenames
> >will be better for it anyway.
> >There is a reason no one has complained about this before, and while I
> >haven't run a study or anything, I strongly suspect its that
> "everyone"
> >else is already on the "no tildes in filenames" bandwagon, so this
> >behavior, even if technically a bug, has no ability to cause them
> >problems.
> >Best,
> >~G
> >On Tue, Jun 11, 2019 at 8:25 AM Frank Schwidom <[1]schwi...@gmx.net>
> >wrote:
> >
> >  Hi,
> >
> >  yes, I have seen this package and it has the same tilde expanding
> >  problem.
> >
> >  Please excuse me I will cc this answer to r-help and r-devel to
> keep the
> >  discussion running.
> >
> >  Kind regards,
> >  Frank Schwidom
> >
> >  On 2019-06-11 09:12:36, Gábor Csárdi wrote:
> >  > Just in case, have you seen the fs package?
> >  > [2]https://fs.r-lib.org/
> >  >
> >  > Gabor
> >  >
> >  > On Tue, Jun 11, 2019 at 7:51 AM Frank Schwidom <[3]
> schwi...@gmx.net>
> >  wrote:
> >  > >
> >  > > Hi,
> >  > >
> >  > > to get rid of any possible filename modification I started a
> little
> >  project to cover my usecase:
> >  > >
> >  > > [4]https://github.com/schwidom/simplefs
> >  > >
> >  > > This is my first R package, suggestions and a review are
> welcome.
> >  > >
> >  > > Thanks in advance
> >  > > Frank Schwidom
> >  > >
> >  > > On 2019-06-07 09:04:06, Richard O'Keefe wrote:
> >  > > >How can expanding tildes anywhere but the beginning of a
> file
> >  name NOT be
> >  > > >considered a bug?
> >  > > >On Thu, 6 Jun 2019 at 23:04, Ivan Krylov
> >  <[1][5]krylov.r...@gmail.com> wrote:
> >  > > >
> >  > > >  On Wed, 5 Jun 2019 18:07:15 +0200
> >  > > >  Frank Schwidom <[2][6]schwi...@gmx.net> wrote:
> >  > > >
> >  > > >  > +> path.expand("a ~ b")
> >  > > >  > [1] "a /home/user b"
> >  > > >
> >  > > >  > How can I switch off any file crippling activity?
> >  > > >
> >  > > >  It doesn't seem to be possible if readline is enabled and
> >  works
> >  > > >  correctly.
> >  > > >
> >  > > >  Calls to path.expand [1] end up [2] in R_ExpandFileName
> [3],
> >  which
> >  > > >  calls R_ExpandFileName_readline [4], which uses
> libreadline
> >  function
> >  > > >  tilde_expand [5]. tilde_expand seems to be designed to
> expand
> >  '~'
> >  > > >  anywhere in the string it is handed, i.e. operate on
> whole
> >  command
> >  > > >  lines, not file paths.
> >  > > >
> >  > > >  I am taking the liberty of Cc-ing R-devel in case this
> can be
> >  > > >  considered a bug.
> >  > > >
> >  > > >  --
> >  > > >  Best regards,
> >  > > >  Ivan
> >  > > >
> >  > > >  [1]
> >  > > >
> >  [3][7]
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/names.c#L807
> >  > > >
> >  > > >  [2]
> >  > > >
> >  [4][8]
> https://github.com/wch/r-source/blob/12d1d2d232d84aa355e48b81180a0e2c6f2f/src/main/platform.c#L1915
> >  > > >
> >  > 

Re: [R] Calculating date difference in days

2019-05-22 Thread William Dunlap via R-help
You can use units<- to change the time units of the difference.  E.g.,

> d <- as.POSIXlt("2018-03-10") -  as.POSIXlt("2018-03-09 02:00:00")
> d
Time difference of 22 hours
> units(d) <- "days"
> d
Time difference of 0.917 days
>
> units(d) <- "mins"
> d
Time difference of 1320 mins
> units(d) <- "secs"
> d
Time difference of 79200 secs
> units(d) <- "weeks"
> d
Time difference of 0.1309524 weeks

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, May 22, 2019 at 2:44 PM  wrote:

> R Help
>
> I have a function to calculate a date difference in days but my results
> come
> back in hours.  I suspect I am using the as.POSIXlt function incorrectly .
>
> Suggestions?
>
> # Start time of data to be considered
> start_day <- "2016-04-30"
>
> # Make event and sequence IDs into factors
> elapsed_days <- function(end_date, start_date){
>   ed <- as.POSIXlt(end_date)
>   sd <- as.POSIXlt(start_date)
>   ed-sd
> }
>
> trans_sequence$eventID <- elapsed_days(trans_sequence$Date, start_day)
>
>
> > trans_sequence
> # A tibble: 39 x 5
> # Groups:   Emitter [15]
>Emitter DateSIZE Geohash
> eventID
> 
> 
>  1   1 2016-05-0112 A;B;C;D;E;F;G;H;I;J;K;L
> 19 hours
>  2   1 2016-05-02 5 A;B;C;D;E
> 43 hours
>  3   1 2016-05-0511 A;B;C;D;E;F;G;H;I;J;K
> 115 hours
>  4   2 2016-05-01 9 C;D;E;F;G;H;I;J;K
> 19 hours
>  5   2 2016-05-02 3 F;G;H
> 43 hours
>  6   2 2016-05-05 3 L;M;N
> 115 hours
>  7   3 2016-05-01 3 L;M;N
> 19 hours
>  8   3 2016-05-02 3 I;J;K
> 43 hours
>  9   3 2016-05-0425
> A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y  91 hours
> 10   3 2016-05-05 7 O;P;Q;R;S;T;U
> 115 hours
>
> Jeff Reichman
>
>
> [[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 separate string from numbers in a large txt file

2019-05-17 Thread William Dunlap via R-help
The pattern I gave worked for the lines that you originally showed from the
data file ('a'), before you put commas into them.  If the name is either of
the form "" or "***" then the "(<[^>]*>)" needs to be changed so
something like "(<[^>]*>|[*]{3})".

The " " at the start of the imported data may come from the byte order
mark that Windows apps like to put at the front of a text file in UTF-8 or
UTF-16 format.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, May 17, 2019 at 11:53 AM Michael Boulineau <
michael.p.boulin...@gmail.com> wrote:

> This seemed to work:
>
> > a <- readLines ("hangouts-conversation-6.csv.txt")
> > b <- sub("^(.{10}) (.{8}) (<.+>) (.+$)", "\\1,\\2,\\3,\\4", a)
> > b [1:84]
>
> And the first 85 lines looks like this:
>
> [83] "2016-06-28 21:02:28 *** Jane Doe started a video chat"
> [84] "2016-06-28 21:12:43 *** John Doe ended a video chat"
>
> Then they transition to the commas:
>
> > b [84:100]
>  [1] "2016-06-28 21:12:43 *** John Doe ended a video chat"
>  [2] "2016-07-01,02:50:35,,hey"
>  [3] "2016-07-01,02:51:26,,waiting for plane to Edinburgh"
>  [4] "2016-07-01,02:51:45,,thinking about my boo"
>
> Even the strange bit on line 6347 was caught by this:
>
> > b [6346:6348]
> [1] "2016-10-21,10:56:29,,John_Doe"
> [2] "2016-10-21,10:56:37,,Admit#8242"
> [3] "2016-10-21,11:00:13,,Okay so you have a discussion"
>
> Perhaps most awesomely, the code catches spaces that are interposed
> into the comment itself:
>
> > b [4]
> [1] "2016-01-27,09:15:20,,Hey "
>   > b [85]
> [1] "2016-07-01,02:50:35,,hey"
>
> Notice whether there is a space after the "hey" or not.
>
> These are the first two lines:
>
> [1] "2016-01-27 09:14:40 *** Jane Doe started a video chat"
> [2] "2016-01-27,09:15:20, Doe>,
> https://lh3.googleusercontent.com/-_WQF5kRcnpk/Vqj7J4aK1jI/AVA/GVqutPqbSuo/s0/be8ded30-87a6-4e80-bdfa-83ed51591dbf
> "
>
> So, who knows what happened with the  at the beginning of [1]
> directly above. But notice how there are no commas in [1] but there
> appear in [2]. I don't see why really long ones like [2] directly
> above would be a problem, were they to be translated into a csv or
> data frame column.
>
> Now, with the commas in there, couldn't we write this into a csv or a
> data.frame? Some of this data will end up being garbage, I imagine.
> Like in [2] directly above. Or with [83] and [84] at the top of this
> discussion post/email. Embarrassingly, I've been trying to convert
> this into a data.frame or csv but I can't manage to. I've been using
> the write.csv function, but I don't think I've been getting the
> arguments correct.
>
> At the end of the day, I would like a data.frame and/or csv with the
> following four columns: date, time, person, comment.
>
> I tried this, too:
>
> > c <- strcapture("^([[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}
> + [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}) +(<[^>]*>) *(.*$)",
> + a, proto=data.frame(stringsAsFactors=FALSE, When="",
> Who="",
> + What=""))
>
> But all I got was this:
>
> > c [1:100, ]
> When  Who What
> 1 
> 2 
> 3 
> 4 
> 5 
> 6 
>
> It seems to have caught nothing.
>
> > unique (c)
>   When  Who What
> 1   
>
> But I like that it converted into columns. That's a really great
> format. With a little tweaking, it'd be a great code for this data
> set.
>
> Michael
>
> On Fri, May 17, 2019 at 8:20 AM William Dunlap via R-help
>  wrote:
> >
> > Consider using readLines() and strcapture() for reading such a file.
> E.g.,
> > suppose readLines(files) produced a character vector like
> >
> > x <- c("2016-10-21 10:35:36  What's your login",
> >   "2016-10-21 10:56:29  John_Doe",
> >   "2016-10-21 10:56:37  Admit#8242",
> >   "October 23, 1819 12:34  I am not an angel")
> >
> > Then you can make a data.frame with columns When, Who, and What by
> > supplying a pattern containing three parenthesized capture expressions:
> > > z <- strcapture("^([[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}
> > [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}) +(<[^>]*>) *(.*$)",
> >  x, proto=data.frame(stringsAsFactors=FALSE, When="", Who=""

Re: [R] how to separate string from numbers in a large txt file

2019-05-17 Thread William Dunlap via R-help
Consider using readLines() and strcapture() for reading such a file.  E.g.,
suppose readLines(files) produced a character vector like

x <- c("2016-10-21 10:35:36  What's your login",
  "2016-10-21 10:56:29  John_Doe",
  "2016-10-21 10:56:37  Admit#8242",
  "October 23, 1819 12:34  I am not an angel")

Then you can make a data.frame with columns When, Who, and What by
supplying a pattern containing three parenthesized capture expressions:
> z <- strcapture("^([[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}
[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}) +(<[^>]*>) *(.*$)",
 x, proto=data.frame(stringsAsFactors=FALSE, When="", Who="",
What=""))
> str(z)
'data.frame':   4 obs. of  3 variables:
 $ When: chr  "2016-10-21 10:35:36" "2016-10-21 10:56:29" "2016-10-21
10:56:37" NA
 $ Who : chr  "" "" "" NA
 $ What: chr  "What's your login" "John_Doe" "Admit#8242" NA

Lines that don't match the pattern result in NA's - you might make a second
pass over the corresponding elements of x with a new pattern.

You can convert the When column from character to time with as.POSIXct().

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, May 16, 2019 at 8:30 PM David Winsemius 
wrote:

>
> On 5/16/19 3:53 PM, Michael Boulineau wrote:
> > OK. So, I named the object test and then checked the 6347th item
> >
> >> test <- readLines ("hangouts-conversation.txt)
> >> test [6347]
> > [1] "2016-10-21 10:56:37  Admit#8242"
> >
> > Perhaps where it was getting screwed up is, since the end of this is a
> > number (8242), then, given that there's no space between the number
> > and what ought to be the next row, R didn't know where to draw the
> > line. Sure enough, it looks like this when I go to the original file
> > and control f "#8242"
> >
> > 2016-10-21 10:35:36  What's your login
> > 2016-10-21 10:56:29  John_Doe
> > 2016-10-21 10:56:37  Admit#8242
>
>
> An octothorpe is an end of line signifier and is interpreted as allowing
> comments. You can prevent that interpretation with suitable choice of
> parameters to `read.table` or `read.csv`. I don't understand why that
> should cause anu error or a failure to match that pattern.
>
> > 2016-10-21 11:00:13  Okay so you have a discussion
> >
> > Again, it doesn't look like that in the file. Gmail automatically
> > formats it like that when I paste it in. More to the point, it looks
> > like
> >
> > 2016-10-21 10:35:36  What's your login2016-10-21 10:56:29
> >  John_Doe2016-10-21 10:56:37  Admit#82422016-10-21
> > 11:00:13  Okay so you have a discussion
> >
> > Notice Admit#82422016. So there's that.
> >
> > Then I built object test2.
> >
> > test2 <- sub("^(.{10}) (.{8}) (<.+>) (.+$)", "//1,//2,//3,//4", test)
> >
> > This worked for 84 lines, then this happened.
>
> It may have done something but as you later discovered my first code for
> the pattern was incorrect. I had tested it (and pasted in the results of
> the test) . The way to refer to a capture class is with back-slashes
> before the numbers, not forward-slashes. Try this:
>
>
>  > newvec <- sub("^(.{10}) (.{8}) (<.+>) (.+$)", "\\1,\\2,\\3,\\4", chrvec)
>  > newvec
>   [1] "2016-07-01,02:50:35,,hey"
>   [2] "2016-07-01,02:51:26,,waiting for plane to Edinburgh"
>   [3] "2016-07-01,02:51:45,,thinking about my boo"
>   [4] "2016-07-01,02:52:07,,nothing crappy has happened, not really"
>   [5] "2016-07-01,02:52:20,,plane went by pretty fast, didn't sleep"
>   [6] "2016-07-01,02:54:08,,no idea what time it is or where I am
> really"
>   [7] "2016-07-01,02:54:17,,just know it's london"
>   [8] "2016-07-01,02:56:44,,you are probably asleep"
>   [9] "2016-07-01,02:58:45,,I hope fish was fishy in a good eay"
> [10] "2016-07-01 02:58:56 "
> [11] "2016-07-01 02:59:34 "
> [12] "2016-07-01,03:02:48,,British security is a little more
> rigorous..."
>
>
> I made note of the fact that the 10th and 11th lines had no commas.
>
> >
> >> test2 [84]
> > [1] "2016-06-28 21:12:43 *** John Doe ended a video chat"
>
> That line didn't have any "<" so wasn't matched.
>
>
> You could remove all none matching lines for pattern of
>
> datestimes"<"">"
>
>
> with:
>
>
> chrvec <- chrvec[ grepl("^.{10} .{8} <.+> .+$)", chrvec)]
>
>
> Do read:
>
> ?read.csv
>
> ?regex
>
>
> --
>
> David
>
>
> >> test2 [85]
> > [1] "//1,//2,//3,//4"
> >> test [85]
> > [1] "2016-07-01 02:50:35  hey"
> >
> > Notice how I toggled back and forth between test and test2 there. So,
> > whatever happened with the regex, it happened in the switch from 84 to
> > 85, I guess. It went on like
> >
> > [990] "//1,//2,//3,//4"
> >   [991] "//1,//2,//3,//4"
> >   [992] "//1,//2,//3,//4"
> >   [993] "//1,//2,//3,//4"
> >   [994] "//1,//2,//3,//4"
> >   [995] "//1,//2,//3,//4"
> >   [996] "//1,//2,//3,//4"
> >   [997] "//1,//2,//3,//4"
> >   [998] "//1,//2,//3,//4"
> >   [999] "//1,//2,//3,//4"
> > [1000] "//1,//2,//3,//4"
> >
> > up until line 1000, then I reached max.print.
>
> > Michael
> >
> > On Thu, May 16, 2019 at 1:05 PM David Winsemius 
> wrote:

Re: [R] Question about addressing a data frame

2019-04-25 Thread William Dunlap via R-help
is.na(DF) is a matrix for a data.frame DF.  The semantics of '[" are
different for matrices
and data.frame and that can cause confusion

> DF <- data.frame(X=c(101,NA,NA), Y=c("one","two",NA),
row.names=c("i","ii","iii"))
> is.na(DF) # returns a matrix when given a data.frame
X Y
i   FALSE FALSE
ii   TRUE FALSE
iii  TRUE  TRUE
> which(is.na(DF)) # returns a vector when given a data.frame
[1] 2 3 6
> which(is.na(DF), arr.ind=TRUE) # returns a length(dim(matrix))-column
matrix when given an array
row col
ii2   1
iii   3   1
iii   3   2
> DF[!is.na(DF)] # as.matrix(DF)[ !is.na(as.matrix(DF)) ]
[1] "101" "one" "two"

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Apr 25, 2019 at 9:27 AM Nitu, Laurentiu <
laurentiu.n...@fraserhealth.ca> wrote:

> Hello,
>
>
> I have this data frame [algae] in the package DMwR. I thought I understand
> how to refer an element but I cannot explain...
>
> is.na(algae) is giving us the a logical vector with TRUE being the na's.
> which(is.na(algae)) gives the positions on the elements in the data frame
> where is.na returns TRUE.
>
>
> However which(is.na(algae)) returns
>
>
> [1]  648  838  862 1055 1056 1057 1058 1059 1060 1061 1062 1161 1199 1262
> 1399 1462 1599 1662 1799 1828 1999 2055 2056 2057 2058 2059 2060 2061 2062
> 2063
> [31] 2116 2184 2199
>
> Weirs since:
>
>
> > dim(algae)
>
> [1] 200  18
>
>
> If I refer back algae[which(is.na(algae))) I get a vector of NA's...
>
> What are the values returned by which(is.na(algae))?
>
> Thanks a lot for your help
>
> [[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] Problems w/ creating object

2019-04-22 Thread William Dunlap via R-help
Also, recall that on Windows each drive has its own root directory so the
meaning of "/some/file" depends on where your working directory is at the
moment.  E.g.,

> setwd("C:/tmp")
> cat(file="junk.txt",1:10)
> file.info("/tmp/junk.txt")
  size isdir mode   mtime   ctime
 atime exe
/tmp/junk.txt   20 FALSE  666 2019-04-22 14:20:06 2018-05-15 09:38:02
2018-05-15 09:38:02  no
> setwd("Z:/") # I've mapped Z: to a network location
> file.info("/tmp/junk.txt")
  size isdir mode mtime ctime atime  exe
/tmp/junk.txt   NANA
> file.info("C:/tmp/junk.txt") # add drive-colon to file name
size isdir mode   mtime   ctime
   atime exe
C:/tmp/junk.txt   20 FALSE  666 2019-04-22 14:20:06 2018-05-15 09:38:02
2018-05-15 09:38:02  no

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Apr 22, 2019 at 2:09 PM William Dunlap  wrote:

>   file.info(
> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt" )
> would tell about the permissions on the file, if it exists (and give NA's
> if it did not).
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Mon, Apr 22, 2019 at 2:00 PM David Winsemius 
> wrote:
>
>>
>> On 4/22/19 11:49 AM, Spencer Brackett wrote:
>> > Hello R users,
>> >
>> > I am trying to create an object out of some data a colleague sent my
>> way,
>> > so to duplicate the following code...
>> >
>> > library(data.table)
>> > anno = as.data.frame(fread(file =
>> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep
>> ="\t",
>> > header = T))
>>
>>
>> At first glance it appeared that you sent the list a rather extensive
>> bit of code and asked us to figure something out, but after looking at
>> the error message it instead appears the it was the first effort at
>> reading data from disk that threw an error. So the rest of the code is
>> at best unnecessary and at worst seriously distracting (to us and more
>> crucially to you).
>>
>> You should run your code one line at a time so you and the rest of us
>> are not completely distracted. This was the error message:
>>
>> > anno = as.data.frame(fread(file =
>>
>> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep ="\t",
>> header = T))
>> Error in fread(file =
>> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt",  :
>>File '/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt' does
>> not exist or is non-readable.
>>
>> You claim this file exists, but I'm uncertain how convincing that
>> assertion should be "scored". What do either of these show?
>>
>>   list.files(pattern =".txt$")
>>
>> # Or
>>
>> "mapper.txt" %in% list.files( paste0 ( getwd(),
>> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K"))
>>
>> --
>>
>> David.
>>
>>
>> PS Please learn to post in plain-text. It didn't cause a problem this
>> time but it probably will at some time in the future.
>>
>> > meth = read.table(file =
>> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/27K/GBM.txt", sep  ="\t",
>> > header = T, row.names = 1)
>> > meth = as.matrix(meth)
>> > """ the loop just formats the methylation column names to match
>> format"""
>> > colnames(meth) = sapply(colnames(meth), function(i){
>> >c1 = strsplit(i,split = '.', fixed = T)[[1]]
>> >c1[4] = paste(strsplit(c1[4],split = "",fixed =
>> T)[[1]][1:2],collapse =
>> > "")
>> >paste(c1,collapse = ".")
>> > })
>> > exp = read.table(file =
>> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/RNAseq/GBM.txt", sep =
>> "\t",
>> > header = T, row.names = 1)
>> > exp = as.matrix(exp)
>> > c = intersect(colnames(exp),colnames(meth))
>> > exp = exp[,c]
>> > meth = meth[,c]
>> > m = apply(meth, 1, function(i){
>> >log2(i/(1-i))
>> > })
>> > m = t(as.matrix(m))
>> > an = anno[anno$probe %in% rownames(m),]
>> > an = an[an$gene %in% rownames(exp),]
>> > an = an[an$location %in% c("TSS200","TSS1500"),]
>> >
>> > p = apply(an,1,function(i){
>> >tryCatch(summary(lm(exp[as.character(i[2]),] ~
>> > m[as.cha

Re: [R] Problems w/ creating object

2019-04-22 Thread William Dunlap via R-help
  file.info( "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt" )
would tell about the permissions on the file, if it exists (and give NA's
if it did not).

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Apr 22, 2019 at 2:00 PM David Winsemius 
wrote:

>
> On 4/22/19 11:49 AM, Spencer Brackett wrote:
> > Hello R users,
> >
> > I am trying to create an object out of some data a colleague sent my way,
> > so to duplicate the following code...
> >
> > library(data.table)
> > anno = as.data.frame(fread(file =
> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep ="\t",
> > header = T))
>
>
> At first glance it appeared that you sent the list a rather extensive
> bit of code and asked us to figure something out, but after looking at
> the error message it instead appears the it was the first effort at
> reading data from disk that threw an error. So the rest of the code is
> at best unnecessary and at worst seriously distracting (to us and more
> crucially to you).
>
> You should run your code one line at a time so you and the rest of us
> are not completely distracted. This was the error message:
>
> > anno = as.data.frame(fread(file =
>
> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep ="\t",
> header = T))
> Error in fread(file =
> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt",  :
>File '/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt' does
> not exist or is non-readable.
>
> You claim this file exists, but I'm uncertain how convincing that
> assertion should be "scored". What do either of these show?
>
>   list.files(pattern =".txt$")
>
> # Or
>
> "mapper.txt" %in% list.files( paste0 ( getwd(),
> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K"))
>
> --
>
> David.
>
>
> PS Please learn to post in plain-text. It didn't cause a problem this
> time but it probably will at some time in the future.
>
> > meth = read.table(file =
> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/27K/GBM.txt", sep  ="\t",
> > header = T, row.names = 1)
> > meth = as.matrix(meth)
> > """ the loop just formats the methylation column names to match format"""
> > colnames(meth) = sapply(colnames(meth), function(i){
> >c1 = strsplit(i,split = '.', fixed = T)[[1]]
> >c1[4] = paste(strsplit(c1[4],split = "",fixed = T)[[1]][1:2],collapse
> =
> > "")
> >paste(c1,collapse = ".")
> > })
> > exp = read.table(file =
> > "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/RNAseq/GBM.txt", sep = "\t",
> > header = T, row.names = 1)
> > exp = as.matrix(exp)
> > c = intersect(colnames(exp),colnames(meth))
> > exp = exp[,c]
> > meth = meth[,c]
> > m = apply(meth, 1, function(i){
> >log2(i/(1-i))
> > })
> > m = t(as.matrix(m))
> > an = anno[anno$probe %in% rownames(m),]
> > an = an[an$gene %in% rownames(exp),]
> > an = an[an$location %in% c("TSS200","TSS1500"),]
> >
> > p = apply(an,1,function(i){
> >tryCatch(summary(lm(exp[as.character(i[2]),] ~
> > m[as.character(i[1]),]))$coefficient[2,4], error= function(e)NA)
> > })
> > t = apply(an,1,function(i){
> >tryCatch(summary(lm(exp[as.character(i[2]),] ~
> > m[as.character(i[1]),]))$coefficient[2,3], error= function(e)NA)
> > })
> > an1 =cbind(an,p)
> > an1 = cbind(an1,t)
> > an1$q = p.adjust(as.numeric(an1$p))
> > summary(lm(exp["MAOB",] ~ m["cg00121904",]$coefficient[2,c(3:4)]
> > ###
> >
> > m2 = m
> > ll = list()
> > for(i in colnames(m2)){
> >str = strsplit(i, split = ".", fixed = T)[[1]]
> >if(str[4] == "11"){
> >
> >}else{
> >  ll = c(ll,i)
> >}
> > }
> > ll = unlist(ll)
> > m2 = m2[,ll]
> > colnames(m2) = sapply(colnames(m2), function(i){
> >str = strsplit(i,split = ".", fixed = T)[[1]]
> >p = paste(str[c(1:3)], collapse = "-")
> > })
> >
> >
> > clin = as.data.frame(fread(file =
> >
> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/survival/FireHose/GBM/GBM.clin.merged.txt",
> > sep = "\t", header = F))
> > clin = t(clin)
> > colnames(clin) = clin[1,]
> > rownames(clin) = toupper(clin[,"patient.bcr_patient_barcode"])
> > clin = clin[2:length(clin[,1]),]
> > #"patient.stage_event.pathologic_stage"
> > clin1 =
> >
> clin[,c("patient.age_at_initial_pathologic_diagnosis","patient.days_to_death","patient.days_to_last_followup","patient.vital_status")]
> > clin1 = cbind(clin1,rep("bla",length(clin1[,1])))
> > clin2 = as.matrix(clin1)
> > colnames(clin2)[length(colnames(clin2))] = "time"
> >
> > for(i in rownames(clin2)){
> >
> >if(clin2[i,"patient.vital_status"] %in% c("alive")){
> >  clin2[i,"patient.vital_status"] =0
> >}else if(clin2[i,"patient.vital_status"] %in% c("dead")){
> >  clin2[i,"patient.vital_status"] =1
> >}else{
> >  clin2[i,"patient.vital_status"] = "NA"
> >}
> >
> >if(is.na(clin2[i,"patient.days_to_last_followup"])){
> >  clin2[i,"time"] = clin2[i,"patient.days_to_death"]
> >}else{
> >  clin2[i,"time"] = clin2[i,"patient.days_to_last_followup"]
> >}
> > }
> >
> > 

Re: [R] problem(s) compiling RWinEdt

2019-04-22 Thread William Dunlap via R-help
Trying adding INSTALL_opts="--no-test-load" to your
install.packages(type="source",...) command.   This package is being too
clever in its .onAttach function.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Apr 22, 2019 at 9:07 AM Evan Cooch  wrote:

> [Note: if this should go to one of the other R maillists,
> apologies...and let me know *which* other list...]
>
>
> I use the WinEdt editor for ll my TeX work, and several years back,
> installed the RWinEdt package in R to allow me to use WinEdt as my R
> edtior as well. Worked, and continues to work, perfectly (currently
> using R 3.5.3, RWinEdt 2.0, and WinEdt 6 -- WinEdt 6 being way behind
> the current release 10.x, but newer version have no new features I felt
> compelled to get by upgrading).
>
> However, with the likelihood I'll need to move some of my Windows 7
> machines -> Windows 10, I wondered about getting the WinEdt-RWinEdt
> combination working on a new machine. So, I built a Win 10 machine,
> clean install, and then did a base install of R 3.5.3 (nothing else
> beyond base). Installed latest RTools, and put it in the path (since
> there doesn't seem to be a Windows binary for RWinEdt). Fired up R with
> admin privileges, and then tried to install RWinEdt. Tried, but...failed
> miserably (console log of one attempt, below). Got the following compile
> failures -- replete with NameSpace errors, and a strange comment that
> RWinEdt is designed for the Windows RGui only (strange, since I *am*
> installing/compiling on a Windows machine).
>
> Being curious, I then re-tried the same exercise using a clean Windows 7
> install. Same issue. Then, retried both, using WinEdt 6. Same issue.
>
>
> So, there seems to be a problem with getting RWinEdt installed. For the
> moment, I'm not too fussed, since I have it working fine on my main work
> machines. However, if I need to setup a new machine in future (Win 7 or
> Win 10), I'd like to be able to do a 'fresh' install of R, WinEdt and
> RWinEdt.
>
> Any suggestions?
>
> Thanks...
>
>
> 
>
> --- Please select a CRAN mirror for use in this session ---
> Package which is only available in source form, and may need
>compilation of C/C++/Fortran: ‘RWinEdt’
> installing the source package ‘RWinEdt’
>
> trying URL 'https://cran.mtu.edu/src/contrib/RWinEdt_2.0-6.tar.gz'
> Content type 'application/x-gzip' length 801476 bytes (782 KB)
> downloaded 782 KB
>
> * installing *source* package 'RWinEdt' ...
> ** package 'RWinEdt' successfully unpacked and MD5 sums checked
> ** libs
>
> *** arch - i386
> c:/Rtools/mingw_32/bin/gcc  -I"C:/PROGRA~1/R/R-35~1.3/include"
> -DNDEBUG  -O3 -Wall  -std=gnu99 -mtune=generic -c ismdi.c -o
> ismdi.o
> c:/Rtools/mingw_32/bin/gcc -shared -s -static-libgcc -o RWinEdt.dll
> tmp.def ismdi.o -lRgraphapp -LC:/PROGRA~1/R/R-35~1.3/bin/i386 -lR
> installing to C:/Program Files/R/R-3.5.3/library/RWinEdt/libs/i386
>
> *** arch - x64
> c:/Rtools/mingw_64/bin/gcc  -I"C:/PROGRA~1/R/R-35~1.3/include"
> -DNDEBUG  -O2 -Wall  -std=gnu99 -mtune=generic -c ismdi.c -o
> ismdi.o
> c:/Rtools/mingw_64/bin/gcc -shared -s -static-libgcc -o RWinEdt.dll
> tmp.def ismdi.o -lRgraphapp -LC:/PROGRA~1/R/R-35~1.3/bin/x64 -lR
> installing to C:/Program Files/R/R-3.5.3/library/RWinEdt/libs/x64
> ** R
> ** inst
> ** byte-compile and prepare package for lazy loading
> ** help
> *** installing help indices
>converting help for package 'RWinEdt'
>  finding HTML links ... done
>  WinEdt  html
>  ismdi   html
> ** building package indices
> ** installing vignettes
> 'RWinEdt.Rnw'
>
> ** testing if installed package can be loaded
> *** arch - i386
> Error: package or namespace load failed for 'RWinEdt':
>   .onAttach failed in attachNamespace() for 'RWinEdt', details:
>call: fun(libname, pkgname)
>error:
> R-WinEdt is designed only for *RGui* on Windows!
> Error: loading failed
> Execution halted
> *** arch - x64
> Error: package or namespace load failed for 'RWinEdt':
>   .onAttach failed in attachNamespace() for 'RWinEdt', details:
>call: fun(libname, pkgname)
>error:
> R-WinEdt is designed only for *RGui* on Windows!
> Error: loading failed
> Execution halted
> ERROR: loading failed for 'i386', 'x64'
> * removing 'C:/Program Files/R/R-3.5.3/library/RWinEdt'
> In R CMD INSTALL
>
> The downloaded source packages are in
> ‘C:\Users\egc\AppData\Local\Temp\RtmpiYRr5e\downloaded_packages’
> Warning message:
> In install.packages(NULL, .libPaths()[1L], dependencies = NA, type = type)
> :
>installation of package ‘RWinEdt’ had non-zero exit status
>
> __
> 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 

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] lm fails on some large input

2019-04-18 Thread William Dunlap via R-help
This sort of data arises quite easily if you deal with time/dates around
now.  E.g.,

> d <- data.frame(
+ when = seq(as.POSIXct("2017-09-29 18:22:01"), by="secs", len=10),
+ measurement = log2(1:10))
> coef(lm(data=d, measurement ~ when))
   (Intercept)   when
2.1791061114716954 NA
> as.numeric(d$when)[1:2]
[1] 1506734521 1506734522

There are problems with the time units (seconds vs. hours) if you subtract
off a time because the units of -.POSIXt depend on the data:

> coef(lm(data=d, measurement ~ I(when - min(when
(Intercept) I(when - min(when))
0.68327571513124297 0.33240675474232279
> coef(lm(data=d, measurement ~ I(when - as.POSIXct("2017-09-29
00:00:00"
(Intercept) I(when - as.POSIXct("2017-09-29
00:00:00"))
   -21978.3837546251634
1196.6643170736229


Hence you have to use difftime and specify the units

> coef(lm(data=d, measurement ~ difftime(when, as.POSIXct("2017-09-29
00:00:00"), units="secs")))
  (Intercept)
  -2.1978383754612696e+04
difftime(when, as.POSIXct("2017-09-29 00:00:00"), units = "secs")
   3.3240675474248449e-01
> coef(lm(data=d, measurement ~ difftime(when, min(when), units="secs")))
  (Intercept) difftime(when, min(when), units =
"secs")
  0.68327571513124297
 0.33240675474232279



Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Apr 18, 2019 at 8:24 AM Michael Dewey 
wrote:

> Perhaps subtract 1506705766 from y?
>
> Saying some other software does it well implies you know what the
> _correct_ answer is here but I would question what that means with this
> sort of data-set.
>
> On 17/04/2019 07:26, Dingyuan Wang wrote:
> > Hi,
> >
> > This input doesn't have any interesting properties except y is unix
> > time. Spreadsheets can do this well.
> > Is this a bug that lm can't do x ~ y?
> >
> > R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
> > Copyright (C) 2018 The R Foundation for Statistical Computing
> > Platform: x86_64-pc-linux-gnu (64-bit)
> >
> >  > x = c(79.744, 123.904, 87.29601, 116.352, 67.71201, 72.96001,
> > 101.632, 108.928, 94.08)
> >  > y = c(1506705739.385, 1506705766.895, 1506705746.293, 1506705761.873,
> > 1506705734.743, 1506705735.351, 1506705756.26, 1506705761.307,
> > 1506705747.372)
> >  > m = lm(x ~ y)
> >  > summary(m)
> >
> > Call:
> > lm(formula = x ~ y)
> >
> > Residuals:
> >   Min   1Q   Median   3Q  Max
> > -27.0222 -14.9902  -0.6542  14.1938  29.1698
> >
> > Coefficients: (1 not defined because of singularities)
> >  Estimate Std. Error t value Pr(>|t|)
> > (Intercept)   94.734  6.511   14.55 4.88e-07 ***
> > y NA NA  NA   NA
> > ---
> > Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> >
> > Residual standard error: 19.53 on 8 degrees of freedom
> >
> >  > summary(lm(y ~ x))
> >
> > Call:
> > lm(formula = y ~ x)
> >
> > Residuals:
> >  Min  1Q  Median  3Q Max
> > -2.1687 -1.3345 -0.9466  1.3826  2.6551
> >
> > Coefficients:
> >   Estimate Std. Error   t value Pr(>|t|)
> > (Intercept) 1.507e+09  3.294e+00 4.574e+08  < 2e-16 ***
> > x   6.136e-01  3.413e-02 1.798e+01 4.07e-07 ***
> > ---
> > Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> >
> > Residual standard error: 1.885 on 7 degrees of freedom
> > Multiple R-squared:  0.9788,Adjusted R-squared:  0.9758
> > F-statistic: 323.3 on 1 and 7 DF,  p-value: 4.068e-07
> >
> > __
> > 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.
> >
> > ---
> > This email has been checked for viruses by AVG.
> > https://www.avg.com
> >
> >
>
> --
> Michael
> http://www.dewey.myzen.co.uk/home.html
>
> __
> 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] Why is it not possible to cut a tree returned by Agnes or Diana by height?

2019-04-14 Thread William Dunlap via R-help
I think cutree() only works on things inheriting from class 'hclust' and
agnes, et al do not produce such things.  There are as.hclust methods for
the output of agnes so you might try
cutree( as.hclust( agnes(...)), h)
instead of
cutree( agnes(...), h)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sun, Apr 14, 2019 at 4:12 PM Leszek Nowina  wrote:

> > asdf = data.frame(x=c(1,2,3), y=c(4,5,6), z=c(7,8,9))
> > cutree(agnes(asdf), h=100)
> Error in cutree(agnes(asdf), h = 100) :
>   the 'height' component of 'tree' is not sorted (increasingly)
> > cutree(diana(asdf), h=100)
> Error in cutree(diana(asdf), h = 100) :
>   the 'height' component of 'tree' is not sorted (increasingly)
>
> I'm not sure if I understand why this is the case.
>
> This is what I want: Cluster stuff by the //distances//, **not** by
> how many clusters I want to have.
>
> If two things are further from each other than X, they should go to
> different clusters. Otherwise, the same cluster.
>
> Is it unreasonable what I'm asking for? I image if I was to manually
> implement Agnes or Diana this would go like that: stop joining
> clusters if the smallest distance between any pair of clusters is
> larger than X (Agnes) or stop dividing clusters if the largest cluster
> has a diameter of X (Diana); but since both methods always join/divide
> to the very end I thought using cutree with a height parameter would
> give me what I need. It won't.
>
> Am I missing something?
>
> __
> 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] Are fitted.values available in pglm?

2019-04-12 Thread William Dunlap via R-help
You should ask the maintainer of the package about this:
bug.report(package="pglm") or maintainer("pglm") should give you contact
information.

The help file for pglm seems all wrong - it says pglm's output has class
"pglm" with components like "fitted.values", but the the example calls to
pglm return things of class c("maxLik", "maxim", "list").

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Apr 12, 2019 at 11:09 AM Simon Berrebi  wrote:

> Thank you Bert,
>
> I wasn’t aware of ?str. The only mention of fitted-values is:
>
>  $ maximum: atomic [1:1] -9824
>   ..- attr(*, "fitted.values")= num [1:3460] 1.39 1.3 1.3 1.32 1.27 ...
>
> When I try attr(mymodel$maximum,  ”fitted.values”), I get the same results
> as  attr(AIC(mymodel),  ”fitted.values”), which is a list of number
> starting with (1.39 1.3 1.3 1.32 1.27 …). I don’t see how these can be
> fitted values for the response variable, patents, which are larger numbers
> (30, 3, 48, 1, 2, 32, …). Is this output not supped to represent the fitted
> values for patents?
>
> Another way to obtain fitted values would be using residuals.?pglm also
> includes residuals in its list of elements. However, str(mymodel) does not
> mention residuals. Does that mean it’s just not there?
>
> - Simon
>
> > On Apr 12, 2019, at 10:44 AM, Bert Gunter 
> wrote:
> >
> > ?fitted
> > ?predict
> > ## This is what one usually does, but I have not checked pglm.
> >
> > You also need to get friendly with ?str
> >
> > ... and probably also spend time with an R tutorial or two to become
> familiar with R modeling conventions.
> >
> > 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 Fri, Apr 12, 2019 at 7:35 AM Simon Berrebi  > wrote:
> > Hello everyone,
> >
> > I am using the pglm function in R to fit a Poisson fixed-effects model.
> According to the documentation <
> https://cran.r-project.org/web/packages/pglm/pglm.pdf <
> https://cran.r-project.org/web/packages/pglm/pglm.pdf>>, the pglm object
> should have fitted.values. However, fitted.values(mymodel) returns "NULL".
> >
> > When I run AIC(mymodel) the AIC is followed by "attr(,"fitted.values")"
> and a long list of number. I have included an example below and attached a
> text file with the output.
> >
> > Are these fitted values? If so, is there a way to obtain them directly?
> Can I also get fitted-values based on a synthetic dataset (i.e. predict())?
> >
> > install.packages("pglm")
> > library(pglm)
> >
> > data("PatentsRDUS", package="pglm")
> >
> >
> >  mymodel <- pglm(patents ~   log(rd)  + as.numeric(year)+
> I(log(capital72)*as.numeric(year)) , PatentsRDUS,
> >  family = poisson(link=log), model = "within", index = c("cusip",
> "year"))
> >
> >  fitted.values(mymodel)
> >  AIC(mymodel)
> >
> > Cordially,
> > —
> > Dr. Simon J Berrebi
> > Postdoctoral Fellow
> > Civil and Environmental Engineering
> > Georgia Institute of Technology
> >
> >
> >
> >
> >
> >
> >
> >
> > __
> > R-help@r-project.org  mailing list -- To
> UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help <
> https://stat.ethz.ch/mailman/listinfo/r-help>
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html <
> 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] Fwd: high p values

2019-03-19 Thread William Dunlap via R-help
Any reasonable test of whether two samples differ should be scale and
location invariant.  E.g., if you measure temperature it should not matter
if you units are degrees Fahrenheit or micro-Kelvins.  Thus saying the
medians are 3500 and 6200 is equivalent to saying they are 100.035 and
100.062: it does not tell use how different the samples are.  You need to
consider how much overlap there is.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Mar 19, 2019 at 9:48 AM javed khan  wrote:

> Hi
>
> This is my function:
>
> wilcox.test(A,B, data = data, paired = FALSE)
>
> It gives me high p value, though the median of A column is 6900 and B
> column is 3500.
>
> Why it gives p value high if there is a difference in the median?
>
> 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 list recursive package dependency prior to installation/upgrade of a package

2019-03-14 Thread William Dunlap via R-help
available.packages() and installed.packages() map package names to version
and a lot of other things.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Mar 14, 2019 at 1:03 PM Sebastien Bihorel <
sebastien.biho...@cognigencorp.com> wrote:

> That is great!
>
> Is there a way to know version required in the dependent packages?
>
> ------
> *From: *"William Dunlap" 
> *To: *"Sebastien Bihorel" 
> *Cc: *r-help@r-project.org
> *Sent: *Thursday, March 14, 2019 3:50:58 PM
> *Subject: *Re: [R] How to list recursive package dependency prior to
> installation/upgrade of a package
>
> > tools::package_dependencies("lme4")
> $lme4
>  [1] "Matrix""methods"   "stats" "graphics"  "grid"
> "splines"
>  [7] "utils" "parallel"  "MASS"  "lattice"   "boot"  "nlme"
>
> [13] "minqa" "nloptr""Rcpp"  "RcppEigen"
>
> > tools::package_dependencies("lme4", recursive=TRUE)
> $lme4
>  [1] "Matrix""methods"   "stats" "graphics"  "grid"
> "splines"
>  [7] "utils" "parallel"  "MASS"  "lattice"   "boot"  "nlme"
>
> [13] "minqa" "nloptr""Rcpp"  "RcppEigen" "grDevices"
>
> Use reverse=TRUE to list packages that depend on the given package.
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Thu, Mar 14, 2019 at 12:09 PM Sebastien Bihorel <
> sebastien.biho...@cognigencorp.com> wrote:
>
>> Hi
>>
>> Is there an elegant way to recursive list all dependencies of a package
>> prior to its installation or upgrade?
>>
>> I am particularly interested in finding which of the packages currently
>> installed in my test/production environment would require an upgrade prior
>> to actual installation/upgrade of a package.
>>
>> Can the packrat package help with this?
>>
>> Thank you
>>
>> __
>> 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 list recursive package dependency prior to installation/upgrade of a package

2019-03-14 Thread William Dunlap via R-help
> tools::package_dependencies("lme4")
$lme4
 [1] "Matrix""methods"   "stats" "graphics"  "grid"  "splines"
 [7] "utils" "parallel"  "MASS"  "lattice"   "boot"  "nlme"
[13] "minqa" "nloptr""Rcpp"  "RcppEigen"

> tools::package_dependencies("lme4", recursive=TRUE)
$lme4
 [1] "Matrix""methods"   "stats" "graphics"  "grid"  "splines"
 [7] "utils" "parallel"  "MASS"  "lattice"   "boot"  "nlme"
[13] "minqa" "nloptr""Rcpp"  "RcppEigen" "grDevices"

Use reverse=TRUE to list packages that depend on the given package.
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Mar 14, 2019 at 12:09 PM Sebastien Bihorel <
sebastien.biho...@cognigencorp.com> wrote:

> Hi
>
> Is there an elegant way to recursive list all dependencies of a package
> prior to its installation or upgrade?
>
> I am particularly interested in finding which of the packages currently
> installed in my test/production environment would require an upgrade prior
> to actual installation/upgrade of a package.
>
> Can the packrat package help with this?
>
> Thank you
>
> __
> 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] Sorting vector based on pairs of comparisons

2019-03-14 Thread William Dunlap via R-help
This is called topological sorting in some circles.  The function below
will give you one ordering that is consistent with the contraints but not
all possible orderings.  I couldn't find such a function in core R so I
wrote one a while back based on Kahn's algorithm, as described in Wikipedia.

> Smaller <- c("ASD", "DFE", "ASD", "SDR", "EDF", "ASD")
> Larger <- c("SDR", "EDF", "KLM", "KLM", "SDR", "EDF")
> matComp <- cbind(Smaller, Larger)
> sortTopologically(matComp, unique(as.vector(matComp)))
[1] "ASD" "DFE" "EDF" "SDR" "KLM"

Bill Dunlap
TIBCO Software
wdunlap tibco.com

sortTopologically <- function(edgeMatrix, V)
{
# edgeMatrix is 2-column matrix which describes a partial
#   ordering of a set of vertices. The first column is the 'from'
vertex,
#   the second the 'to' vertex.
# V is the vector of all the vertices in the graph.
#
# Return a vector, L, consisting of the vertices in
#   V in an order consistent with the partial ordering
#   described by edgeMatrix.
# Throw an error if such an ordering is not possible.
#
# Use Kahn's algorithm (
https://en.wikipedia.org/wiki/Topological_sorting).
#
# Note that disconnected vertices will not be mentioned in edgeMatrix,
#   but will be in V.
stopifnot(is.matrix(edgeMatrix),
  ncol(edgeMatrix)==2,
  !any(is.na(edgeMatrix)),
  !any(is.na(V)),
  all(as.vector(edgeMatrix) %in% V))
L <- V[0] # match the type of the input
S <- setdiff(V, edgeMatrix[, 2])
V <- setdiff(V, S)
while(length(S) > 0) {
n <- S[1]
# cat("Adding", n, "to L", "\n")
L <- c(L, n)
S <- S[-1]
mRow <- edgeMatrix[,1] == n
edgeMatrix <- edgeMatrix[ !mRow, , drop=FALSE ]
S <- c(S, setdiff(V, edgeMatrix[,2]))
V <- setdiff(V, S)
}
if (nrow(edgeMatrix) > 0) {
stop("There are cycles in the dependency graph")
}
L
}


On Thu, Mar 14, 2019 at 4:30 AM Pedro Conte de Barros 
wrote:

> Dear All,
>
> This should be a quite established algorithm, but I have been searching
> for a couple days already without finding any satisfactory solution.
>
> I have a matrix defining pairs of Smaller-Larger arbitrary character
> values, like below
>
> Smaller <- c("ASD", "DFE", "ASD", "SDR", "EDF", "ASD")
>
> Larger <- c("SDR", "EDF", "KLM", "KLM", "SDR", "EDF"
>
> matComp <- cbind(Smaller, Larger)
>
> so that matComp looks like this
>
>   Smaller Larger
> [1,] "ASD"   "SDR"
> [2,] "DFE"   "EDF"
> [3,] "ASD"   "KLM"
> [4,] "SDR"   "KLM"
> [5,] "EDF"   "SDR"
> [6,] "ASD"   "EDF"
>
> This matrix establishes six pairs of "larger than" relationships that
> can be used to sort the unique values in the matrix,
>
>  > unique(as.vector(matComp))
> [1] "ASD" "DFE" "SDR" "EDF" "KLM"
>
> Specifically, I would like to get this:
>
> sorted <- c("ASD", "DFE", "EDF", "SDR", "KLM")
>
> or, equally valid (my matrix does not have the full information):
>
> sorted <- c("DFE", "ASD", "EDF", "SDR", "KLM")
>
> Preferably, I would get the different combinations of the unique values
> that satisfy the "larger than" conditions in the matrix...
>
>
> I am sure this is a trivial problem, but I could not find any algorithm
> to solve it.
>
> Any help would be highly appreciated
>
> __
> 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] inverse of which()

2019-02-27 Thread William Dunlap via R-help
The inverse of which() would have to know the length of the logical vector
to create.  The function could be
   invWhich <- function(whichTrue, length) {
   stopifnot(length <= max(whichTrue), !anyNA(whichTrue))
   v <- logical(length)
   v[whichTrue] <- TRUE
   v
   }
It isn't quite an inverse, as which() treats NA and FALSE the same.

Much of the time dealing with the logical vector (e.g, grepl() instead of
grep()) is less error prone than using which() to convert to indices of the
TRUE values.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 27, 2019 at 3:04 PM Ed Siefker  wrote:

> Given a vector of booleans, chich() will return indices that are TRUE.
>
> Given a vector of indices, how can I get a vector of booleans?
>
> My intent is to do logical operations on the output of grep().  Maybe
> there's a better way to do this?
>
> Thanks
> -Ed
>
> __
> 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] Which dependency list to build first?

2019-02-27 Thread William Dunlap via R-help
Did you use 'R CMD ldd .../later.so', as I recommended?

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 27, 2019 at 12:51 PM Rich Shepard 
wrote:

> On Wed, 27 Feb 2019, William Dunlap wrote:
>
> > The package will not load. The only reason to do test load is to examine
> > why the package's .so file cannot be loaded. We know there is at least
> one
> > function or data symbol that it cannot find, __atomic_fetch_add_8, which
> > may be from boost::atomic. The ldd command may give some hints about
> > missing libraries.
>
> Bill,
>
> Yes, it does. libR.so is not found:
> # ldd later.so
> linux-gate.so.1 (0xb76df000)
> libR.so => not found
>
> However, R runs and libR.so is found here:
> /usr/lib/R/lib/libR.so
> and was last accessed
> -rwxr-xr-x 1 root root 3331940 Dec 23 10:00 /usr/lib/R/lib/libR.so*
>
> Should I rebuild and reinstall R-3.5.2?
>
> Thanks again,
>
> Rich
>
> __
> 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] Which dependency list to build first?

2019-02-27 Thread William Dunlap via R-help
The package will not load.  The only reason to do test load is to examine
why the package's .so file cannot be loaded.  We know there is at least one
function or data symbol that it cannot find,  __atomic_fetch_add_8, wihch
may be from boost::atomic.  The ldd command may give some hints about
missing libraries.
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 27, 2019 at 11:56 AM Rich Shepard 
wrote:

> On Wed, 27 Feb 2019, William Dunlap wrote:
>
> > The syntax is either
> >install.packages("later", type="source",
> INSTALL_opts="--no-test-load")
> > from within R (perhaps with repos=NULL if from a local directory) or
> >R CMD INSTALL --no-test-load later
> > from outside of R, where 'later' must be a directory.
>
> Bill,
>
> Thank you very much. I read ?install.packages and saw all the options but
> had no idea what to use.
>
> Boy howdy! Removing the load testing allowed the package to install:
>
> installing to /usr/lib/R/library/later/libs
> ** R
> ** inst
> ** byte-compile and prepare package for lazy loading
> ** help
> *** installing help indices
> ** building package indices
> ** installing vignettes
> * DONE (later)
>
> Is it worth exploring why testing loading failed here for this package?
>
> Best regards,
>
> Rich
>
> __
> 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] Which dependency list to build first?

2019-02-27 Thread William Dunlap via R-help
Using the syntax 'install.packages("later") --no-test-load'

The syntax is either
install.packages("later", type="source", INSTALL_opts="--no-test-load")
from within R (perhaps with repos=NULL if from a local directory) or
R CMD INSTALL --no-test-load later
from outside of R, where 'later' must be a directory.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 27, 2019 at 11:14 AM Rich Shepard 
wrote:

> On Wed, 27 Feb 2019, William Dunlap wrote:
>
> > Add the --no-test-load option to the install command and the unloadable
> .so
> > file should be left there so you can look at its dependencies with, e.g.,
> > 'R CMD ldd .../libs/later.so'.
>
> Bill,
>
> Using the syntax 'install.packages("later") --no-test-load' still produces
> the same result:
>
> ** testing if installed package can be loaded
> Error: package or namespace load failed for ‘later’ in dyn.load(file,
> DLLpath = DLLpath, ...):
>   unable to load shared object '/usr/lib/R/library/later/libs/later.so':
>/usr/lib/R/library/later/libs/later.so: undefined symbol:
> __atomic_fetch_add_8
> Error: loading failed
> Execution halted
> ERROR: loading failed
>
> The later package was installed so why it's not updating now puzzles me.
> I'm
> running R-3.5.2 on Slackware-14.2.
>
> Regards,
>
> Rich
>
> __
> 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] Which dependency list to build first?

2019-02-27 Thread William Dunlap via R-help
Add the --no-test-load option to the install command and the unloadable .so
file should be left there so you can look at its dependencies with, e.g.,
'R CMD ldd .../libs/later.so'.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 27, 2019 at 9:40 AM Rich Shepard 
wrote:

> On Wed, 27 Feb 2019, Rainer Krug wrote:
>
> > I am sure, you have uninstalled the package completely and tried it
> again?
>
> Rainer,
>
> Yes. Just did so with the same result: R could not load the shared library.
>
> > Have you tried at looking at the shared objects required by
> > `/usr/lib/R/library/later/libs/later.so` using ldd ?
>
> Because later was removed and could not be rebuilt, there is no later.so to
> be queried for dependencies.
>
> I'll look again at later's dependencies and ensure they're all rebuilt.
>
> Regards,
>
> Rich
>
> __
> 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] Second attempt: Cannot reproduce tutorial results

2019-02-25 Thread William Dunlap via R-help
Do you see anything wrong with this line?
   titles <- c(title, extractTitle(data.combined[i, "name"])) }

Hint - plural or singular?

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Feb 25, 2019 at 11:38 AM Jason Hernandez via R-help <
r-help@r-project.org> wrote:

> Okay, I switched to plain text. Let's see if people can see this better.
> I have come back to trying to learn R after a long time away, and have
> begun with the YouTube tutorial videos by David Langer, as seen on
> "Introduction to Data Science with R - Data Analysis Part 1." I am using R
> Studio with R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
>
> Around 1:16:00 in the video Langer creates a new variable using an else if
> loop:
>
> extractTitle <- function(name) {
>  name <- as.character(name)
>  if(length(grep("Miss.", name)) > 0) {
>return("Miss.")
>  } else if(length(grep("Master.", name)) > 0) {
>return("Master.")
>  } else if(length(grep("Mrs.", name)) > 0) {
>return("Mrs.")
>  } else if(length(grep("Mr.", name)) > 0) {
>return("Mr.")
>  } else { return("Other.") }}
>
> titles <- NULL
> for(i in 1:nrow(data.combined)) {
>  titles <- c(title, extractTitle(data.combined[i, "name"])) }
>
> data.combined$title <- as.factor(titles)
>
> There are two problems I see in my attempt to replicate this. First, the
> data.combined set contains 1309 names, but when I try to create the
> variable "titles" using this code, it creates a list of 2. When I use
> View(titles), what comes up is the first item on the list is
>
> function (main = NULL, sub = NULL, xlab = NULL, ylab = NULL, line = NA,
> outer = FALSE, ...)
>
> and the second item in the list is just the title "Master."
>
> The second problem is that after I enter data.combined$title <-
> as.factor(titles) I get the error message
>
> Error in sort.list(y) : 'x' must be atomic for 'sort.list' Have you called
> 'sort' on a list?
>
> If I try changing the as.factor to as.vector, I get
>
> Error in `$<-.data.frame`(`*tmp*`, title, value = list(function (main =
> NULL, : replacement has 2 rows, data has 1309
>
> I have checked and rechecked my code, and it is identical to Langer's.
> What is wrong here?
>
> __
> 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] Ghost variables

2019-02-25 Thread William Dunlap via R-help
Doesn't that mean that your script is incomplete, that it needs to make
those variables?

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Feb 25, 2019 at 10:32 AM  wrote:

> Fellow R-gonauts:
>
> I frequently erase/remove all the objects in my current environment so can
> I re-run scripts to ensure that analyses are complete, error-free, and
> accurate.
> However, sometimes when I re-rerun a script I get warning messages (see
> below for example)  regarding some variables (objects) when these
> variables do not exist in my current environment.
> These ghost variables had existed at one time, but were subsequently
> removed by the rm(list=ls()) command or by the broom icon in RStudio.
>
> What's happening and how do I exorcise the ghosts?
>
>
> Warning messages:
> 1: Unknown or uninitialised column: 'K'.
> 2: Unknown or uninitialised column: 'NDAfit'.
> 3: Unknown or uninitialised column: 'NDAfit'.
> 4: Unknown or uninitialised column: 'NDAfit'.
> 5: Unknown or uninitialised column: 'NDAfit'.
> 6: Unknown or uninitialised column: 'NDAfit'.
> 7: Unknown or uninitialised column: 'NDAobs'.
>
> Joe Lucke
> [[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] Save creates huge files, dump doesn't

2019-02-20 Thread William Dunlap via R-help
Also, note that the function
   function(x) x
   
has no free variables so it doesn't matter what environment encloses it.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 20, 2019 at 7:47 AM William Dunlap  wrote:

> object@transforms@transforms$PC1.all@f
> function(x) x
> 
> Do you know how to 'see' what's in 0x3314db8 ?
>
> ls.str(all=TRUE, environment(object@transforms@transforms$PC1.all@f)
>
> will list the names, types, summaries, etc. of the objects in that
> environment.
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Wed, Feb 20, 2019 at 12:20 AM Lars Velten  wrote:
> >
> > Dear Bill, dear all,
> >
> > yes that seems to be it.  The problem orginates from objects of class
> transformMap from package flowCore
> >
> > > object_size(object@transforms@transforms$PC1.all@f)
> > 174 MB
> > > object.size(object@transforms@transforms$PC1.all@f)
> > 1160 bytes
> >
> > object@transforms@transforms$PC1.all@f
> >
> > function(x) x
> > 
> >
> > Do you know how to 'see' what's in 0x3314db8 ? Might then drop a line to
> flowCore's developer, this behavior cannot be intended - especially here
> where f literally is just identity :-)
> >
> > Best wishes,
> >
> > Lars
> >
> > On 19. Feb 2019, at 21:30, William Dunlap  wrote:
> >
> > One reason save() makes bigger files than dump() is that save() saves
> environments associated with functions that are saved and those
> environments may contain large datasets that are not really needed.
> >
> > Bill Dunlap
> > TIBCO Software
> > wdunlap tibco.com
> >
> >
> > On Tue, Feb 19, 2019 at 11:59 AM Jeff Newmiller <
> jdnew...@dcn.davis.ca.us> wrote:
> >>
> >> Make a reproducible example that focuses on the save/load aspect of the
> size problem. You may need to experiment with which variables need to be in
> the save file in order to trigger the behavior. Your example might have to
> involve sending us a link to a large file, but that size may dissuade busy
> experts from tackling it so paring it down by experimentation could be in
> your best interest.
> >>
> >> There is some expected behavior that can lead to larger files than the
> original in-memory data, but offhand I am unaware of any explanation for
> those files then using less space when re-loaded into memory than they
> occupy on disk.
> >>
> >> On February 18, 2019 11:51:11 AM PST, Lars Velten 
> wrote:
> >> >Dear list,
> >> >I noticed an extremely odd behavior... I have a rather complex shiny
> >> >app which allows the user to store his/her state which internally
> >> >obviously triggers as call to save as follows
> >> >save(list=c("plots","gates","populations","cg",
> >> >"genelists","colorscores",  "proj", "actds"),file=fname)
> >> >this was all working fine until some time ago (?!?) files created by
> >> >this command became several hundred MBs big... even thought the
> >> >cumulative size of all objects in memory after load() is in the 10s of
> >> >kB.
> >> >Changing to
> >> >dump(list=c("plots","gates","populations","cg",
> >> >"genelists","colorscores",  "proj", "actds"),file=fname)
> >> >solved the problem, output was then only 10s of kB.
> >> >(Why/when) is this behavior intended?
> >> >Best wishes,
> >> >Lars
> >> >
> >> >   [[alternative HTML version deleted]]
> >> >
> >> >__
> >> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> >https://stat.ethz.ch/mailman/listinfo/r-help
> >> >PLEASE do read the posting guide
> >> >http://www.R-project.org/posting-guide.html
> >> >and provide commented, minimal, self-contained, reproducible code.
> >>
> >> --
> >> Sent from my phone. Please excuse my brevity.
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
>

[[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] Save creates huge files, dump doesn't

2019-02-20 Thread William Dunlap via R-help
object@transforms@transforms$PC1.all@f
function(x) x

Do you know how to 'see' what's in 0x3314db8 ?

ls.str(all=TRUE, environment(object@transforms@transforms$PC1.all@f)

will list the names, types, summaries, etc. of the objects in that
environment.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Feb 20, 2019 at 12:20 AM Lars Velten  wrote:
>
> Dear Bill, dear all,
>
> yes that seems to be it.  The problem orginates from objects of class
transformMap from package flowCore
>
> > object_size(object@transforms@transforms$PC1.all@f)
> 174 MB
> > object.size(object@transforms@transforms$PC1.all@f)
> 1160 bytes
>
> object@transforms@transforms$PC1.all@f
>
> function(x) x
> 
>
> Do you know how to 'see' what's in 0x3314db8 ? Might then drop a line to
flowCore's developer, this behavior cannot be intended - especially here
where f literally is just identity :-)
>
> Best wishes,
>
> Lars
>
> On 19. Feb 2019, at 21:30, William Dunlap  wrote:
>
> One reason save() makes bigger files than dump() is that save() saves
environments associated with functions that are saved and those
environments may contain large datasets that are not really needed.
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Tue, Feb 19, 2019 at 11:59 AM Jeff Newmiller 
wrote:
>>
>> Make a reproducible example that focuses on the save/load aspect of the
size problem. You may need to experiment with which variables need to be in
the save file in order to trigger the behavior. Your example might have to
involve sending us a link to a large file, but that size may dissuade busy
experts from tackling it so paring it down by experimentation could be in
your best interest.
>>
>> There is some expected behavior that can lead to larger files than the
original in-memory data, but offhand I am unaware of any explanation for
those files then using less space when re-loaded into memory than they
occupy on disk.
>>
>> On February 18, 2019 11:51:11 AM PST, Lars Velten 
wrote:
>> >Dear list,
>> >I noticed an extremely odd behavior... I have a rather complex shiny
>> >app which allows the user to store his/her state which internally
>> >obviously triggers as call to save as follows
>> >save(list=c("plots","gates","populations","cg",
>> >"genelists","colorscores",  "proj", "actds"),file=fname)
>> >this was all working fine until some time ago (?!?) files created by
>> >this command became several hundred MBs big... even thought the
>> >cumulative size of all objects in memory after load() is in the 10s of
>> >kB.
>> >Changing to
>> >dump(list=c("plots","gates","populations","cg",
>> >"genelists","colorscores",  "proj", "actds"),file=fname)
>> >solved the problem, output was then only 10s of kB.
>> >(Why/when) is this behavior intended?
>> >Best wishes,
>> >Lars
>> >
>> >   [[alternative HTML version deleted]]
>> >
>> >__
>> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> >https://stat.ethz.ch/mailman/listinfo/r-help
>> >PLEASE do read the posting guide
>> >http://www.R-project.org/posting-guide.html
>> >and provide commented, minimal, self-contained, reproducible code.
>>
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

[[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] Save creates huge files, dump doesn't

2019-02-19 Thread William Dunlap via R-help
One reason save() makes bigger files than dump() is that save() saves
environments associated with functions that are saved and those
environments may contain large datasets that are not really needed.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Feb 19, 2019 at 11:59 AM Jeff Newmiller 
wrote:

> Make a reproducible example that focuses on the save/load aspect of the
> size problem. You may need to experiment with which variables need to be in
> the save file in order to trigger the behavior. Your example might have to
> involve sending us a link to a large file, but that size may dissuade busy
> experts from tackling it so paring it down by experimentation could be in
> your best interest.
>
> There is some expected behavior that can lead to larger files than the
> original in-memory data, but offhand I am unaware of any explanation for
> those files then using less space when re-loaded into memory than they
> occupy on disk.
>
> On February 18, 2019 11:51:11 AM PST, Lars Velten 
> wrote:
> >Dear list,
> >I noticed an extremely odd behavior... I have a rather complex shiny
> >app which allows the user to store his/her state which internally
> >obviously triggers as call to save as follows
> >save(list=c("plots","gates","populations","cg",
> >"genelists","colorscores",  "proj", "actds"),file=fname)
> >this was all working fine until some time ago (?!?) files created by
> >this command became several hundred MBs big... even thought the
> >cumulative size of all objects in memory after load() is in the 10s of
> >kB.
> >Changing to
> >dump(list=c("plots","gates","populations","cg",
> >"genelists","colorscores",  "proj", "actds"),file=fname)
> >solved the problem, output was then only 10s of kB.
> >(Why/when) is this behavior intended?
> >Best wishes,
> >Lars
> >
> >   [[alternative HTML version deleted]]
> >
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> --
> Sent from my phone. Please excuse my brevity.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] POSIXlt class and lapply

2019-02-14 Thread William Dunlap via R-help
Somewhere between R-3.3.3 and R-3.5.2 a POSIXlt method for as.list() was
added, and lapply probably calls as.list().

> RCompare(methods("as.list"))
R version 3.3.3 (2017-03-06)| R version 3.5.1
(2018-07-02)
[1] as.list.data.frame  as.list.Date| [1]
as.list.data.frame  as.list.Date
[3] as.list.default as.list.environment | [3] as.list.default
   as.list.environment
[5] as.list.factor  as.list.function| [5] as.list.factor
  as.list.function
[7] as.list.numeric_version as.list.POSIXct | [7]
as.list.numeric_version as.list.POSIXct
see '?methods' for accessing help and source code   | [9] as.list.POSIXlt
| see '?methods' for
accessing help and source code


Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Feb 14, 2019 at 9:45 AM Newell, Paul 
wrote:

> Dear R-helpers,
>
> We have recently upgraded from R-3.3.1 to R-3.5.2.
>
> It seems there has been a change in behaviour of `lapply` and the
> `POSIXlt` class that I cannot find explicitly documented.
>
>
> In R-3.3.1:
>
> > lapply(as.POSIXlt(Sys.Date()), length)
> $sec
> [1] 1
> $min
> [1] 1
> $hour
> [1] 1
> $mday
> [1] 1
> $mon
> [1] 1
> $year
> [1] 1
> $wday
> [1] 1
> $yday
> [1] 1
> $isdst
> [1] 1
>
>
> whereas, in R-3.5.2:
>
> > lapply(as.POSIXlt(Sys.Date()), length)
> [[1]]
> [1] 1
>
>
> Is this change in behaviour intentional?
>
> Realistically, I cannot see anything documented to say that `lapply`
> should behave as per R-3.3.1 on a `POSIXlt` object, so it is/was perhaps
> unwise to rely on it.
>
>
> Best wishes,
> Paul Newell
> __
> 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] Difficulty with "\\" in string functions....

2019-02-11 Thread William Dunlap via R-help
You can also avoid the issue by using the basename and dirname functions.

> Fname1 <- "D:\\Data\\OneDrive\\ISTA Documents\\QT_App\\QT Analysis Input
Data Example WorkBook.xlsx"
> basename(Fname1)
[1] "QT Analysis Input Data Example WorkBook.xlsx"
> dirname(Fname1)
[1] "D:/Data/OneDrive/ISTA Documents/QT_App"

Use normalizePath if you need to convert those / to \ on Windows.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Feb 11, 2019 at 12:26 PM Bernard McGarvey <
mcgarvey.bern...@comcast.net> wrote:

> Brilliant! Thanks a million Ivan.
>
> Lion Bernard McGarvey
>
>
> Director, Fort Myers Beach Lions Foundation, Inc.
>
>
> Retired (Lilly Engineering Fellow).
>
>
> > On February 11, 2019 at 3:13 PM Ivan Krylov 
> wrote:
> >
> >
> > On Mon, 11 Feb 2019 15:01:16 -0500 (EST)
> > Bernard McGarvey  wrote:
> >
> > > Now I try to split it using
> > >
> > >
> > > str_split(Fname1,"\\")
> > >
> > >
> > > but this returns an error
> > >
> > >
> > > Error in stri_split_regex(string, pattern, n = n, simplify =
> > > simplify, : Unrecognized backslash escape sequence in pattern.
> > > (U_REGEX_BAD_ESCAPE_SEQUENCE)
> >
> > This happens because the second parameter of str_split is by default a
> > regular expression, and a backslash has a special meaning in regular
> > expressions: when preceding other characters, it may change the way
> > they are interpreted. (For example, w means a literal "w"
> > character, while \w means "any alphanumeric character". On the
> > other hand, [ starts a character group, but \[ means just an opening
> > square bracket.) See ?regex for more info on that.
> >
> > Since you want a literal backslash, you need to escape it with another
> > backslash: \\
> >
> > But to write a string literal of a double-backslash in R, you need to
> > escape both backslash characters, each with their own backslash: ""
> >
> > ## fname <- "D:\\Data\\OneDrive\\ISTA Documents\\QT_App\\QT Analysis
> > Input Data Example WorkBook.xlsx"
> > ## message("")
> > \\
> > ## str_split(fname, "")
> > [[1]]
> > [1] "D:"
> > [2] "Data"
> > [3] "OneDrive"
> > [4] "ISTA Documents"
> > [5] "QT_App"
> > [6] "QT AnalysisInput Data Example WorkBook.xlsx"
> >
> > You can also avoid all layers of the backslash hell (except the first)
> > if you choose to split by fixed strings instead of regular expressions
> > by using stringr::fixed:
> >
> > ## str_split(fname, fixed("\\"))
> >
> > --
> > 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.
>

[[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] data.frame() versus as.data.frame() applied to a matrix.

2019-02-05 Thread William Dunlap via R-help
I think of the methods of as.data.frame as a helper functions for
data.frame and don't usually call as.data.frame directly.  data.frame()
will call as.data.frame for each of its arguments and then put together the
the results into one big data.frame.

> for(method in
c("as.data.frame.list","as.data.frame.character","as.data.frame.integer","as.data.frame.numeric","as.data.frame.matrix"))
trace(method, quote(str(x)))
Tracing function "as.data.frame.list" in package "base"
Tracing function "as.data.frame.character" in package "base"
Tracing function "as.data.frame.integer" in package "base"
Tracing function "as.data.frame.numeric" in package "base"
Tracing function "as.data.frame.matrix" in package "base"
> d <-
data.frame(Mat=cbind(m1=11:12,M2=13:14),Num=c(15.5,16.6),Int=17:18,List=list(L1=19:20,L2=c(20.2,21.2)))
Tracing as.data.frame.matrix(x[[i]], optional = TRUE) on entry
 int [1:2, 1:2] 11 12 13 14
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:2] "m1" "M2"
Tracing as.data.frame.numeric(x[[i]], optional = TRUE) on entry
 num [1:2] 15.5 16.6
Tracing as.data.frame.integer(x[[i]], optional = TRUE) on entry
 int [1:2] 17 18
Tracing as.data.frame.list(x[[i]], optional = TRUE, stringsAsFactors =
stringsAsFactors) on entry
List of 2
 $ L1: int [1:2] 19 20
 $ L2: num [1:2] 20.2 21.2
Tracing as.data.frame.integer(x[[i]], optional = TRUE) on entry
 int [1:2] 19 20
Tracing as.data.frame.numeric(x[[i]], optional = TRUE) on entry
 num [1:2] 20.2 21.2

If I recall correctly, that is how S did things and Splus tried to use
something like as.data.frameAux for the name of the helper function to
avoid some of the frustration you describe.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Feb 5, 2019 at 2:22 PM Rolf Turner  wrote:

>
> Consider the following:
>
> set.seed(42)
> X <- matrix(runif(40),10,4)
> colnames(X) <- c("a","b","a:x","b:x") # Imitating the output
># of model.matrix().
> D1 <- as.data.frame(X)
> D2 <- data.frame(X)
> names(D1)
> [1] "a"   "b"   "a:x" "b:x"
> names(D2)
> [1] "a"   "b"   "a.x" "b.x"
>
> The names of D2 are syntactically valid; those of D1 are not.
>
> Why should I have expected this phenomenon? :-)
>
> The as.data.frame() syntax seems to me much more natural for converting
> a matrix to a data frame, yet it doesn't get it quite right, sometimes,
> in respect of the names.
>
> Is there some reason that as.data.frame() does not apply make.names()?
> Or was this just an oversight?
>
> cheers,
>
> Rolf Turner
>
> --
> Honorary Research Fellow
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
> __
> 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] Why is there error in as.POSIXlt.character when using strftime()?

2019-02-02 Thread William Dunlap via R-help
Note that the first unparsable element is the first with a 13 in the second
field, which is out of range for the month entry.  If you look at the the
whole date/time output by the first 19 elements you will see that you need
to tell it the order of the year, month, and day

> as.POSIXlt(dat[1:19])
 [1] "0007-12-15 11:32:00 LMT" "0007-12-15 11:42:00 LMT"
 [3] "0007-12-15 12:17:00 LMT" "0007-12-15 12:31:00 LMT"
 [5] "0007-12-15 12:50:00 LMT" "0007-12-15 14:10:00 LMT"
 [7] "0007-12-15 14:19:00 LMT" "0007-12-15 14:59:00 LMT"
 [9] "0007-12-15 15:57:00 LMT" "0007-12-15 16:00:00 LMT"
[11] "0007-12-15 16:46:00 LMT" "0007-12-15 16:51:00 LMT"
[13] "0007-12-15 17:35:00 LMT" "0007-12-15 17:59:00 LMT"
[15] "0007-12-15 18:17:00 LMT" "0007-12-15 19:07:00 LMT"
[17] "0007-12-15 19:08:00 LMT" "0007-12-15 19:31:00 LMT"
[19] "0007-12-15 21:21:00 LMT"
> as.POSIXlt(dat, format="%m/%d/%y %H:%M")
 [1] "2015-07-12 11:32:00 PDT" "2015-07-12 11:42:00 PDT"
 [3] "2015-07-12 12:17:00 PDT" "2015-07-12 12:31:00 PDT"
 [5] "2015-07-12 12:50:00 PDT" "2015-07-12 14:10:00 PDT"
 [7] "2015-07-12 14:19:00 PDT" "2015-07-12 14:59:00 PDT"
 [9] "2015-07-12 15:57:00 PDT" "2015-07-12 16:00:00 PDT"
[11] "2015-07-12 16:46:00 PDT" "2015-07-12 16:51:00 PDT"
[13] "2015-07-12 17:35:00 PDT" "2015-07-12 17:59:00 PDT"
[15] "2015-07-12 18:17:00 PDT" "2015-07-12 19:07:00 PDT"
[17] "2015-07-12 19:08:00 PDT" "2015-07-12 19:31:00 PDT"
[19] "2015-07-12 21:21:00 PDT" "2015-07-13 06:00:00 PDT"
[21] "2015-07-13 06:20:00 PDT" "2015-07-13 06:37:00 PDT"
[23] "2015-07-13 06:40:00 PDT" "2015-07-13 06:46:00 PDT"
[25] "2015-07-13 07:20:00 PDT" "2015-07-13 07:47:00 PDT"
[27] "2015-07-13 07:50:00 PDT" "2015-07-13 07:54:00 PDT"
[29] "2015-07-13 08:11:00 PDT" "2015-07-13 08:23:00 PDT"
[31] "2015-07-13 08:31:00 PDT" "2015-07-13 08:33:00 PDT"
[33] "2015-07-13 08:43:00 PDT" "2015-07-13 09:04:00 PDT"
[35] "2015-07-13 09:09:00 PDT" "2015-07-13 09:30:00 PDT"
[37] "2015-07-13 09:59:00 PDT" "2015-07-13 10:01:00 PDT"
[39] "2015-07-13 10:03:00 PDT" "2015-07-13 10:05:00 PDT"

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sat, Feb 2, 2019 at 6:46 AM C W  wrote:

> Dear R community,
>
> I am working with dates. And I get the following error:
> > strftime(dat[20], format="%H:%M")
> Error in as.POSIXlt.character(as.character(x), ...) :
>   character string is not in a standard unambiguous format
>
> Here's the original data:
> dat <- structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L,
> 13L, 14L, 15L, 16L, 17L, 18L, 19L, 23L, 24L, 25L, 26L, 27L, 28L,
> 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 20L,
> 21L, 22L), .Label = c("7/12/15 11:32", "7/12/15 11:42", "7/12/15 12:17",
> "7/12/15 12:31", "7/12/15 12:50", "7/12/15 14:10", "7/12/15 14:19",
> "7/12/15 14:59", "7/12/15 15:57", "7/12/15 16:00", "7/12/15 16:46",
> "7/12/15 16:51", "7/12/15 17:35", "7/12/15 17:59", "7/12/15 18:17",
> "7/12/15 19:07", "7/12/15 19:08", "7/12/15 19:31", "7/12/15 21:21",
> "7/13/15 10:01", "7/13/15 10:03", "7/13/15 10:05", "7/13/15 6:00",
> "7/13/15 6:20", "7/13/15 6:37", "7/13/15 6:40", "7/13/15 6:46",
> "7/13/15 7:20", "7/13/15 7:47", "7/13/15 7:50", "7/13/15 7:54",
> "7/13/15 8:11", "7/13/15 8:23", "7/13/15 8:31", "7/13/15 8:33",
> "7/13/15 8:43", "7/13/15 9:04", "7/13/15 9:09", "7/13/15 9:30",
> "7/13/15 9:59"), class = "factor")
>
> It seems like things work fine for the first 19 elements,
> > strftime(dat[1:19], format="%H:%M")
>  [1] "11:32" "11:42" "12:17" "12:31" "12:50" "14:10" "14:19" "14:59"
>  [9] "15:57" "16:00" "16:46" "16:51" "17:35" "17:59" "18:17" "19:07"
> [17] "19:08" "19:31" "21:21"
>
> But why not element 20 and on? They *look* the same to me.
>
> What is going on?
>
> Thanks very much!
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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

2019-01-30 Thread William Dunlap via R-help
Searching for 'periodicity' on rseek.org gives, several items from the top,

*periodicity* function | *R* Documentation

https://www.rdocumentation.org/packages/xts/.../0.11.../*periodicity*
Estimate the *periodicity* of a time-series-like object by calculating the
median time between observations in days.
LabeledFunctionDocumentation

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Jan 30, 2019 at 11:27 AM Sarah Goslee 
wrote:

> Hi Nick,
>
> A quick look on rseek.org didn't turn anything up. It would help to
> know what websites you're referring to - they might be loading custom
> code.
>
> Sarah
>
> On Wed, Jan 30, 2019 at 2:17 PM Nick Wray via R-help
>  wrote:
> >
> > I've found references on websites to an R function "periodicity", but
> there's no such built-in function as far as I can see in R studio.  I can't
> find reference to it being part of any package either.  Can anyone help
> with this?
> >
> > Thanks, Nick Wray
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> 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.
>

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

2019-01-30 Thread William Dunlap via R-help
Search with https://rseek.org

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Jan 30, 2019 at 11:17 AM Nick Wray via R-help 
wrote:

> I've found references on websites to an R function "periodicity", but
> there's no such built-in function as far as I can see in R studio.  I can't
> find reference to it being part of any package either.  Can anyone help
> with this?
>
> Thanks, Nick Wray
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] [FORGED] Newbie Question on R versus Matlab/Octave versus C

2019-01-28 Thread William Dunlap via R-help
S (R's predecessor) was designed by and for data analysts.  R generally
follows that tradition.  I think that simulations such as yours are not its
strength, although it can make analyzing (graphically and numerically) the
results of the simulation fun.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jan 28, 2019 at 4:00 PM Alan Feuerbacher 
wrote:

> On 1/28/2019 4:20 PM, Rolf Turner wrote:
> >
> > On 1/29/19 10:05 AM, Alan Feuerbacher wrote:
> >
> >> Hi,
> >>
> >> I recently learned of the existence of R through a physicist friend
> >> who uses it in his research. I've used Octave for a decade, and C for
> >> 35 years, but would like to learn R. These all have advantages and
> >> disadvantages for certain tasks, but as I'm new to R I hardly know how
> >> to evaluate them. Any suggestions?
> >
> > * C is fast, but with a syntax that is (to my mind) virtually
> >incomprehensible.  (You probably think differently about this.)
>
> I've been doing it long enough that I have little problem with it,
> except for pointers. :-)
>
> > * In C, you essentially have to roll your own for all tasks; in R,
> >practically anything (well ...) that you want to do has already
> >been programmed up.  CRAN is a wonderful resource, and there's more
> >on github.
>  >
> > * The syntax of R meshes beautifully with *my* thought patterns; YMMV.
> >
> > * Why not just bog in and try R out?  It's free, it's readily available,
> >and there are a number of good online tutorials.
>
> I just installed R on my Linux Fedora system, so I'll do that.
>
> I wonder if you'd care to comment on my little project that prompted
> this? As part of another project, I wanted to model population growth
> starting from a handful of starting individuals. This is exponential in
> the long run, of course, but I wanted to see how a few basic parameters
> affected the outcome. Using Octave, I modeled a single person as a
> "cell", which in Octave has a good deal of overhead. The program
> basically looped over the entire population, and updated each person
> according to the parameters, which included random statistical
> variations. So when the total population reached, say 10,000, and an
> update time of 1 day, the program had to execute 10,000 x 365 update
> operations for each year of growth. For large populations, say 100,000,
> the program did not return even after 24 hours of run time.
>
> So I switched to C, and used its "struct" declaration and an array of
> structs to model the population. This allowed the program to complete in
> under a minute as opposed to 24 hours+. So in line with your comments, C
> is far more efficient than Octave.
>
> How do you think R would fare in this simulation?
>
> Alan
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> __
> 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] TIme Zone error

2019-01-26 Thread William Dunlap via R-help
> Sys.setenv(TZ="US/Eastern")
> as.POSIXlt("2019-01-26 01:19")
[1] "2019-01-26 01:19:00 EST"
> Sys.setenv(TZ="Asia/Calcutta")
> as.POSIXlt("2019-01-26 01:19")
[1] "2019-01-26 01:19:00 IST"

(Sys.getenv("Asia/Calcutta") returns the value of the environment variable
"Asia/Calcutta".  It does not set a value.)
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sat, Jan 26, 2019 at 1:15 PM Christofer Bogaso <
bogaso.christo...@gmail.com> wrote:

> Hi,
>
> I want to set a specific Timezone for my R environment, with below syntax:
>
> > Sys.getenv("Asia/Calcutta")
>
> [1] ""
>
> >
> But it sets to some blank timezone.
>
> I checked with OlsonNames(), to see available zones for R, where I found
> "Asia/Calcutta" available.
>
> I idea why R failed to set timezone properly?
>
> Thanks for your time.
>
> [[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] Diff'ing 2 strings

2019-01-10 Thread William Dunlap via R-help
> args(tools::Rdiff)
function (from, to, useDiff = FALSE, forEx = FALSE, nullPointers = TRUE,
Log = FALSE)
NULL
> version$version.string
[1] "R version 3.4.3 (2017-11-30)"

(The 'tools' package is not attached by default, so use ::.)
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Jan 10, 2019 at 8:39 AM Sebastien Bihorel <
sebastien.biho...@cognigencorp.com> wrote:

> Yep, I did. Got nothing. It does not come with R 3.4.3, which is the
> version I can use.
>
> R CMD Rdiff comes with this version, but it is a shell command not a R
> function. It is meant for diff'ing R output.
>
>
> - Original Message -
> From: "Jeff Newmiller" 
> To: r-help@r-project.org, "Sebastien Bihorel" <
> sebastien.biho...@cognigencorp.com>, "Martin Møller Skarbiniks Pedersen" <
> traxpla...@gmail.com>
> Cc: "R mailing list" 
> Sent: Thursday, January 10, 2019 10:49:15 AM
> Subject: Re: [R] Diff'ing 2 strings
>
> Just type
>
> ?Rdiff
>
> it is in the preinstalled packages that come with R.
>
> On January 10, 2019 7:35:42 AM PST, Sebastien Bihorel <
> sebastien.biho...@cognigencorp.com> wrote:
> >From which the diffobj package?
> >
> >
> >From: "Martin Møller Skarbiniks Pedersen" 
> >To: "Sebastien Bihorel" 
> >Cc: "R mailing list" 
> >Sent: Thursday, January 10, 2019 2:35:15 AM
> >Subject: Re: [R] Diff'ing 2 strings
> >
> >
> >
> >On Sat, Jan 5, 2019, 14:58 Sebastien Bihorel < [
> >mailto:sebastien.biho...@cognigencorp.com |
> >sebastien.biho...@cognigencorp.com ] wrote:
> >
> >
> >Hi,
> >
> >Does R include an equivalent of the linux diff command?
> >
> >
> >
> >
> >yes.
> >?rdiff
> >
> >/martin
> >
> >
> >   [[alternative HTML version deleted]]
> >
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> --
> Sent from my phone. Please excuse my brevity.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] g++ error causes non-zero exit status for package installation

2019-01-05 Thread William Dunlap via R-help
You would get these errors ("R: file or directory not found, version: file
or directory not found...") if you had a ~/.Rprofile file containing the
line 'cat(version$version.string, sep="\n").

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sat, Jan 5, 2019 at 1:23 AM Winfried Moser 
wrote:

> dear community,
>
> i get a *non-zero exit status* installing the survey-package in R version
> 3.5.2 on ubuntu 18.04. the problem seems to be related to *g++* and/or the
> package *minqa*. in the output of the installation procedure i found the
> following g++ related lines:
>
> g++ -I"/usr/share/R/include" -DNDEBUG -I"/home/winfried/rlibs/Rcpp/include"
> -f
> [...]
> g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o
> minqa.so altm
> [...]
> g++: error: R: Datei oder Verzeichnis nicht gefunden
> g++: error: version: Datei oder Verzeichnis nicht gefunden
> g++: error: 3.5.2: Datei oder Verzeichnis nicht gefunden
> g++: error: (2018-12-20): Datei oder Verzeichnis nicht gefunden
>
> can someone help or point me in a direction? several packages, that i use
> frequently, are conserned (survey, lme4, effects)
>
> best, winfried
>
> [[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] Error in names(x) <- value: 'names' attribute must be the same length as the vector in gam function

2019-01-04 Thread William Dunlap via R-help
mgcv::s() does not appear to work with objects of class "Date".  E.g.,

> d <- data.frame(date=seq(as.Date("2018-12-20"),len=10,by="week"),
response=log2(1:10)%%1)
> model <- gam(data=d, response ~ s(date))
Error in names(dat) <- object$term :
  'names' attribute [1] must be the same length as the vector [0]
> traceback()
6: ExtractData(object, data, knots)
5: smooth.construct3(object, data, knots)
4: smoothCon(split$smooth.spec[[i]], data, knots, absorb.cons,
scale.penalty = scale.penalty,
   null.space.penalty = select, sparse.cons = sparse.cons,
diagonal.penalty = diagonal.penalty,
   apply.by = apply.by, modCon = modCon)
3: gam.setup(formula = list(pf = response ~ 1, pfok = 1, smooth.spec = list(
   list(term = "date", bs.dim = -1, fixed = FALSE, dim = 1L,
   p.order = NA, by = "NA", label = "s(date)", xt = NULL,
   id = NULL, sp = NULL)), fake.formula = response ~ 1 +
   date, response = "response", fake.names = "date", pred.names =
"date",
   pred.formula = ~date), pterms = response ~ 1, data = list(
   response = c(0, 0, 0.584962500721156, 0, 0.321928094887362,
   0.584962500721156, 0.807354922057604, 0, 0.169925001442312,
   0.321928094887362), date = c(17885L, 17892L, 17899L, 17906L,
   17913L, 17920L, 17927L, 17934L, 17941L, 17948L)), knots = NULL,
   sp = NULL, min.sp = NULL, H = NULL, absorb.cons = TRUE, sparse.cons
= 0,
   select = FALSE, idLinksBases = TRUE, scale.penalty = TRUE,
   paraPen = NULL, drop.intercept = FALSE)
2: do.call(gsname, list(formula = gp, pterms = pterms, data = mf,
   knots = knots, sp = sp, min.sp = min.sp, H = H, absorb.cons = TRUE,
   sparse.cons = 0, select = select, idLinksBases =
control$idLinksBases,
   scale.penalty = control$scalePenalty, paraPen = paraPen,
   drop.intercept = drop.intercept))
1: gam(data = d, response ~ s(date))

You might work around this by using as.numeric(date) instead of date.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Jan 4, 2019 at 12:29 AM 王 嘉炜  wrote:

> Dear R users,
>
>
> I am using the *mgcv package* to model the ozone pollution concentration
> according to some environmental covariates. The model takes the form :
>
> model1
> <-gam(O3~s(X,Y,bs="tp",k=10)+wd+s(date,bs="cc",k=100)+district,data=mydata,family=
> gaussian(link ="log" ),na.action="na.omit", method="REML")
>
> And here is the strcture of  covariates
> > str(mydata)
> 'data.frame': 7100 obs. of  286 variables:
>  $ date: Date, format: "2016-01-01" "2016-01-01" "2016-01-01"
> ...
>  $ O3  : num  0.0141 0.0149 0.0102 0.0159 0.0186 ...
>  $ district: Factor w/ 10 levels "bc","bh","dl",..: 1 8 7 8 2 6 4
> 4 10 2 ...
>  $ wd  : Factor w/ 16 levels "E","ENE","ESE",..: 13 13 13 13
> 13 2 9 9 11 13 ...
>  $ X   : num  0.389 0.365 1 0.44 0.892 ...
>  $ Y   : num  0.311 0.204 0.426 0.223 0.162 ...
>
> I am stuck on an error in R: 'names' attribute [1] must be the same length
> as the vector [0].
>
> I try to find where the problem is by delete the term of
> "s(date,bs="cc",k=100)" from the fomular and it could work well. It seems
> like  there is something wrong with date field.
>
> I'm not exactly sure how to fix this problem.  Any advice would be greatly
> appreciated!
> Jiawei Wang
> 发自 Outlook
>
> [[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] Problem with system() and source on linux

2018-12-20 Thread William Dunlap via R-help
Isn't 'source' a csh (tcsh, etc.) command?  The sh (bash, etc.) command is
a period, but
you probably will need to use sh constructs in the file (like
VAR=value;exportVAR)
instead of csh constructs (like setenv VAR value).

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Dec 20, 2018 at 7:00 AM Agustin Lobo  wrote:

> Hi!
> I quite often use system() to run other programs from within R, but
> have just hitted
> a problem:
>
> For a given program, I need to set up its environment, which I normally do
> with
> source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile
> from the terminal.
> Now, when I try to do the same from within R, I get:
>
> > system("source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile",
> intern=TRUE)
> sh: 1: source: not found
> Error in system("source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile",  :
>   error in running command
>
> I need this command to set the environment before I actually run the
> program. My idea was saving a simple script from within R  in which
> the first line would be
> source /home/alobo/OTB-6.6.0-Linux64/otbenv.profile
>
> and then run the script with system(), but I get that odd error with
> source. I thought source was just
> a plain linux command, how can it be "not found" from within system()?
>
> Any help much appreciated,
> Thanks
>
>
> --
> Agustin Lobo
> aloboa...@gmail.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.
>

[[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] convert columns of dataframe to same factor levels

2018-12-19 Thread William Dunlap via R-help
You can abuse the S4 class system to do this.

setClass("Size") # no representation, no prototype
setAs(from="character", to="Size", # nothing but a coercion method
  function(from){
ret <- factor(from, levels=c("Small","Medium","Large"), ordered=TRUE)
class(ret) <- c("Size", class(ret))
ret
  })
z <- read.table(colClasses=c("integer", "Size"), text="7 Medium\n5 Large\n3
Large")
dput(z)
#structure(list(V1 = c(7L, 5L, 3L), V2 = structure(c(2L, 3L, 3L
#), .Label = c("Small", "Medium", "Large"), class = c("Size",
#"ordered", "factor"))), class = "data.frame", row.names = c(NA,
#-3L))

I wonder if this behavior is intended or if there is a more sanctioned way
to get read.table(colClasses=...) to make a factor with a specified set of
levels.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Dec 19, 2018 at 3:19 AM Duncan Murdoch 
wrote:

> On 19/12/2018 5:58 AM, Luigi Marongiu wrote:
> > Dear all,
> > I have a data frame with character values where each character is a
> > level; however, not all columns of the data frame have the same
> > characters thus, when generating the data frame with stringsAsFactors
> > = TRUE, the levels are different for each column.
> > Is there a way to provide a single vector of levels and assign the
> > characters so that they match such vector?
> > Is there a way to do that not only when setting the data frame but
> > also when reading data from a file with read.table()?
> >
> > For instance, I have:
> > column_1 = c("A", "B", "C", "D", "E")
> > column_2 = c("B", "B", "C", "E", "E")
> > column_3 = c("C", "C", "D", "D", "C")
> > my.data <- data.frame(column_1, column_2, column_3, stringsAsFactors =
> TRUE)
> >> str(my.data)
> > 'data.frame': 5 obs. of  3 variables:
> >   $ column_1: Factor w/ 5 levels "A","B","C","D",..: 1 2 3 4 5
> >   $ column_2: Factor w/ 3 levels "B","C","E": 1 1 2 3 3
> >   $ column_3: Factor w/ 2 levels "C","D": 1 1 2 2 1
> >
> > Thank you
> >
>
> I don't think read.table() can do it for you automatically.  To do it
> yourself, you need to get a vector of the levels.  If you know this,
> just assign it to a variable; if you don't know it, compute it as
>
>thelevels <- unique(unlist(lapply(my.data, levels)))
>
> Then set the levels of each column to thelevels:
>
>my.data.new <- as.data.frame(lapply(my.data, function(x) {levels(x)
> <- thelevels; x}))
>
> 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.
>

[[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] Drawing a random number

2018-11-29 Thread William Dunlap via R-help
sample( setdiff(10:1000, Vec), size=1)

Also, note that as.integer(runif(1, min, max)) will almost never return max.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Nov 29, 2018 at 11:14 AM Christofer Bogaso <
bogaso.christo...@gmail.com> wrote:

> Hi,
>
> I would like to draw an Integer from a range of [10, 1000] inclusive,
> however that random integer should be outside of a pre-defined vector of
> integers.
>
> Let say I draw an integer as below
>
> as.integer(runif(1, 10, 1000))
>
> and my pre-defined vector is
>
> Vec = c(563, 453, 897, 567)
>
> The policy is my drawn random integer should never be equal to any item
> from Vec
>
> Ofcourse I can use ifelse() to achieve the same, however I was wondering if
> there is any direct way to get the same.
>
> Thanks,
>
> [[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] extrat non diagonal

2018-11-14 Thread William Dunlap via R-help
Another way:

> A <- matrix(1:9,3,3,
dimnames=list(Row=paste0("r",1:3),Col=paste0("c",1:3)))
> A
Col
Row  c1 c2 c3
  r1  1  4  7
  r2  2  5  8
  r3  3  6  9
> matrix( A[row(A)!=col(A)], nrow(A)-1, ncol(A), dimnames=list(NULL,
colnames(A)))
 c1 c2 c3
[1,]  2  4  7
[2,]  3  6  8


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Nov 14, 2018 at 2:32 PM, Richard M. Heiberger 
wrote:

> An even better solution because it has fewer steps.
>
> A <- matrix(1:9, 3, 3)
> A
> B <- A[-1, ]
> B[upper.tri(B, diag=FALSE)] <- A[upper.tri(A)]
> B
>
> > A <- matrix(1:9, 3, 3)
> > A
>  [,1] [,2] [,3]
> [1,]147
> [2,]258
> [3,]369
> > B <- A[-1, ]
> > B[upper.tri(B, diag=FALSE)] <- A[upper.tri(A)]
> > B
>  [,1] [,2] [,3]
> [1,]247
> [2,]368
> >
> On Wed, Nov 14, 2018 at 2:09 PM Richard M. Heiberger 
> wrote:
> >
> > Steve's method is very slick.
> >
> > I think this is a bit easier to understand.
> >
> > A <- matrix(1:9, 3, 3)
> > A
> > B <- matrix(nrow=2, ncol=3)
> > B[lower.tri(B, diag=TRUE)] <- A[lower.tri(A)]
> > B[upper.tri(B, diag=FALSE)] <- A[upper.tri(A)]
> > B
> >
> > > A <- matrix(1:9, 3, 3)
> > > A
> >  [,1] [,2] [,3]
> > [1,]147
> > [2,]258
> > [3,]369
> > > B <- matrix(nrow=2, ncol=3)
> > > B[lower.tri(B, diag=TRUE)] <- A[lower.tri(A)]
> > > B[upper.tri(B, diag=FALSE)] <- A[upper.tri(A)]
> > > B
> >  [,1] [,2] [,3]
> > [1,]247
> > [2,]368
> > >
> > On Wed, Nov 14, 2018 at 11:04 AM S Ellison 
> wrote:
> > >
> > > i) Your code creates w2 but references w1 to create aa.
> > >
> > > So you needed
> > > aa <- matrix(rep(c(0.4, 0.1, 0.2), 3), 3,3)
> > > for a working example.
> > >
> > > ii) This
> > > > matrix(as.numeric(aa)[!as.numeric(aa) %in% diag(aa)],2,3)
> > > removes any value that is present in the diagonal of aa. Look up
> ?"%in%" to see what that does; it returns TRUE whenever anything in
> as.numeric(aa) matches anything in your diagonal. All the values in aa
> match one of c(0.4, 0.1, 0.2). So since your whole matrix consists of these
> three numbers, you told R to leave out everything in aa and then create a
> 2x3 matrix with the result. Hence the NAs
> > >
> > > iii) If you want to extract odd parts of a matrix explicitly, see ?"["
> and particularly the section on indexing using arrays
> > >
> > > iv) You can use logical indexing. In the special case of the diagonal,
> you can use diag() to create a matrix of logicals, logically negate that
> and apply that to your matrix:
> > > aa[ !diag(rep(TRUE, 3)) ]
> > >
> > > and, in twoi rows:
> > > matrix( aa[ !diag(rep(TRUE, 3)) ], 2,3)
> > >
> > > > for examplei have this matrix
> > > > w2<-c(0.1,0.2,0.4,0.2,0.4,0.1)
> > > > aa<-matrix(w1,nrow=3,ncol=3)
> > > > aa
> > > >  [,1] [,2] [,3]
> > > > [1,]  0.4  0.4  0.4
> > > > [2,]  0.1  0.1  0.1
> > > > [3,]  0.2  0.2  0.2
> > > >
> > > > if i use this code
> > > > matrix(as.numeric(aa)[!as.numeric(aa) %in% diag(aa)],2,3)
> > > >
> > > > i will obtaine this matrix[,1] [,2] [,3]
> > > > [1,]   NA   NA   NA
> > > > [2,]   NA   NA   NA
> > > >
> > > > but me i want this matrix[,1] [,2] [,3]
> > > > [1,]  0.1  0.4  0.4
> > > > [2,]  0.2  0.2  0.1
> > > >
> > > > thank you
> > > >
> > > >   [[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.
> > >
> > >
> > > ***
> > > This email and any attachments are confidential. Any use, copying or
> > > disclosure other than by the intended recipient is unauthorised. If
> > > you have received this message in error, please notify the sender
> > > immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com
> > > and delete this message and any copies from your computer and network.
> > > LGC Limited. Registered in England 2991879.
> > > Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
> > > __
> > > 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]]


Re: [R] saveRDS() and readRDS() Why? [solved, pretty much anyway)

2018-11-13 Thread William Dunlap via R-help
Perhaps you got bitten by Dolphin's non-modal dialogs, as described in
https://userbase.kde.org/Dolphin/File_Management:

Non Modal Dialogs

When Moving, Copying or Deleting files/directories the dialog disappears
even when the operation has not yet completed. A progress bar then appears
in the bottom right of the screen, this then disappears also, if you want
see the progress you need to click a small (i) information icon in the
system tray.


Warning
New users who are not used to this way of working (and even experienced
users) can get caught out by this, if you are Moving, Copying or Deleting
large directories then you need to use the icon to monitor the progress of
your operation. If you don't then any subsequent actions you do, may well
use an incomplete file structure resulting in corrupted files. You have
been warned!

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Tue, Nov 13, 2018 at 2:10 PM, p_connolly 
wrote:

> This is getting more strange.
>
> I normally copy from the shared folder to the appropriate directory using
> Dolphin, the KDE file manager.  If instead I use the standard bash cp
> command, no corruption happens -- at least with the limited testing I have
> done.  There also seems to be no problem copying from Linux to Windows.  I
> installed R-3.5.1 for Windows just to eliminate that possible issue.
>
> However, R has *something* to do with it because it was used to make the
> .rds file.  Just how the relationship between the name of the R object and
> the name of the .rds file comes into it, I can't imagine.
>
> Thanks for the suggestion William.
>
>
> On 2018-11-14 06:26, William Dunlap wrote:
>
>> It seems like copying the files corrupted them. How did you copy them
>> (with R
>> or cp or copy or ftp, etc.)?  I don't see how this has anything to do
>> with R.
>>
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com [1]
>> On Mon, Nov 12, 2018 at 7:10 PM, p_connolly
>>  wrote:
>>
> [...]
>
>

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


  1   2   3   4   5   6   7   8   9   10   >