Re: [R] Skip jumps in curve

2024-02-13 Thread Bill Dunlap
Here is the skeleton of a function that lets you supply a function that
will be applied to diff(y) to say if this next point should be connected by
a line to the previous point.

p <- function (x, y = NULL, dy = diff(y), predicate = function(dy)
abs(dy)>2, ...,
  xlab = if (!missing(x)) deparse1(substitute(x)),
  ylab = if (!missing(y)) deparse1(substitute(y)), log = "", type="l")
{
  force(xlab)
  force(ylab)
  xy <- xy.coords(x, y, xlab, ylab, log)
  x <- xy$x
  y <- xy$y
  group <- cumsum( c(TRUE, !is.finite(dy) | predicate(dy)))
  plot(x, y, xlab=xy$xlab, ylab=xy$ylab, log=log, ..., type="n")
  sx <- split(x, group)
  sy <- split(y, group)
  lapply(seq_len(max(group)), function(i)points(type=type, sx[[i]],
sy[[i]]))
  invisible()
}


E.g., plot the tangent function where we know that the discontinuities are
where diff(y) is negative:

par(mfrow=c(2,1))
plot(tan(seq(0,10,by=1/4)), type="b")
p(tan(seq(0,10,by=1/4)), predicate = function(dy)dy<0, type="b")

-Bill

On Tue, Feb 13, 2024 at 10:54 AM Duncan Murdoch 
wrote:

> It should be pretty easy to generalize my version of the `plot.gamma()`
> function to a version of `curve()` with an extra `discontinuities`
> argument.
>
> Duncan Murdoch
>
> On 13/02/2024 1:44 p.m., Leo Mada wrote:
> > Dear Duncan,
> >
> > Thank you very much for the response. I suspected that such an option
> > has not been implemented yet.
> >
> > The plot was very cluttered due to those vertical lines. Fortunately,
> > the gamma function is easy to handle. But the feature remains on my
> > wishlist as useful more in general.
> >
> > Sincerely,
> >
> > Leonard
> >
> > 
> > *From:* Duncan Murdoch 
> > *Sent:* Tuesday, February 13, 2024 6:05 PM
> > *To:* Leo Mada ; r-help@r-project.org
> > 
> > *Subject:* Re: [R] Skip jumps in curve
> > On 13/02/2024 10:29 a.m., Leo Mada via R-help wrote:
> >> Dear R-Users,
> >>
> >> Is there a way to skip over without plotting the jumps/discontinuities
> in curve()?
> >>
> >> I have not seen such an option, but maybe I am missing something.
> >>
> >> plot.gamma = function(xlim = c(-6, -1), ylim = c(-1,3), hline = NULL, n
> = 1000) {
> >> curve(gamma(x), from = xlim[1], to = xlim[2], ylim=ylim, n=n);
> >> if( ! is.null(hline)) abline(h = hline, col = "green");
> >> }
> >>
> >> Euler = 0.57721566490153286060651209008240243079;
> >> plot.gamma(hline = Euler)
> >>
> >> Adding an option to the function curve may be useful:
> >> options = c("warn", "silent", "unconnected")
> >>
> >> This is part of some experiments in math; but that's another topic. For
> latest version:
> >> https://github.com/discoleo/R/blob/master/Math/Integrals.Gamma.Inv.R
> > <https://github.com/discoleo/R/blob/master/Math/Integrals.Gamma.Inv.R>
> >
> > If you know where the discontinuities are, plot multiple times with the
> > discontinuities as endpoints:
> >
> > plot.gamma = function(xlim = c(-6, -1), ylim = c(-1,3), hline = NULL, n
> > = 1000) {
> > start <- floor(xlim[1]):floor(xlim[2])
> > end <- start + 1
> >
> > start[1] <- xlim[1]
> > end[length(end)] <- xlim[2]
> >
> > n <- round(n/length(start))
> >
> > curve(gamma(x), from = start[1], to = end[1], ylim=ylim, n=n, xlim =
> > xlim)
> > for (i in seq_along(start)[-1])
> >   curve(gamma(x), from = start[i], to = end[i], add = TRUE, n)
> > if( ! is.null(hline)) abline(h = hline, col = "green");
> > }
> >
> > Euler = 0.57721566490153286060651209008240243079;
> > plot.gamma(hline = Euler)
> >
> > If you don't know where the discontinuities are, it would be much
> > harder, because discontinuities can be hard to detect unless the jumps
> > are really big.
> >
> > 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] MASS::mvrnorm() on MKL may produce different numbers even when the seed is the same?

2023-08-17 Thread Bill Dunlap
MKL's results can depend on the number of threads running and perhaps other
things.  They blame it on the non-associativity of floating point
arithmetic.  This article gives a way to make results repeatable:

https://www.intel.com/content/www/us/en/developer/articles/technical/introduction-to-the-conditional-numerical-reproducibility-cnr.html

-Bill

On Wed, Aug 16, 2023 at 8:11 PM Shu Fai Cheung 
wrote:

> Hi All,
>
> When addressing an error in one of my packages in the CRAN check at CRAN,
> I found something strange which, I believe, is unrelated to my package.
> I am not sure whether it is a bug or a known issue. Therefore, I would like
> to have advice from experts here.
>
> The error at CRAN check occurred in a test, and only on R-devel with MKL.
> No
> issues on all other platforms. The test compares two sets of random
> numbers,
> supposed to be identical because generated from the same seed. However,
> when
> I tried that in R-devel (2023-08-15 r84957) on Ubuntu 22.04.3 LTS, linked
> to
> MKL (2023.2.0), I found that this is not the case in one situation.
>
> I don't know why but somehow only one particular set of means and
> covariance matrix, among many others in the code, led to that problem.
> Please find
> below the code to reproduce the means and the covariance matrix (pardon me
> for the long code):
>
> mu0 <- structure(c(0.52252416853188655, 0.39883382931927774,
> 1.6296642535174521,
> 2.9045763671121816, -0.19816874840500939, 0.42610841566522556,
> 0.30155498531316366, 1.0339601619394503, 3.4125587827873192,
> 13.125481598475405, 19.275480386183503, 658.94225353462195,
> 1.0997193726987393,
> 9.9980286642877214, 6.4947188998602092, -12.952617780813679,
> 8.4991882784024799, 106.82209520278377, 0.19623712449219838), class =
> c("numeric"))
>
> sigma0 <- structure(c(0.0047010182215945009, 1.4688424622163808e-17,
> -2.5269697696885822e-17,
> -1.2451516929358655e-18, 3.6553475725253408e-19, 3.2092363914356227e-19,
> -2.6341938382508503e-18, 8.6439582878287556e-19, -1.295240602054123e-17,
> 1.1154057497258702e-18, -8.2407621704807367e-33, -1.0891686096304908e-15,
> -2.6800671450262819e-18, -0.0009225142979911, -1.4833018148344697e-16,
> 2.292242132203e-16, -3.5128615476876035e-18, 2.8004770623734002e-33,
> 2.0818099301348832e-34, 1.294907062174661e-17, 0.012788608283099183,
> 1.5603789410838518e-15, 1.0425182851251724e-16, 2.758318745465066e-17,
> -9.7047963858148572e-18, -7.4685438142667792e-17, -1.9426723638193857e-17,
> -7.8775307262071738e-17, -4.0773523140359949e-17, 4.1212975037936416e-18,
> -1.199934828824835e-14, 2.301740948367742e-17, -2.5410883836579325e-18,
> -0.129172198695584, -1.9922957470809647e-14, 1.7077690739402761e-16,
> 1.663702957392817e-30, 5.5362608501514495e-32, -2.5575000656645995e-17,
> 7.3879960338026333e-16, 0.052246980157830372, -0.007670030643844231,
> -1.5468402204507243e-17, 1.0518757786432683e-17, 2.9992131812421253e-16,
> 1.6588830885081527e-17, -8.3276045185697992e-16, -3.3713008849128695e-15,
> 1.5823980389961169e-17, 2.2243227896948194e-15, -3.2071920299461956e-17,
> 5.0187645877462975e-18, -7.4622951185527265e-15, -0.44701112744184102,
> -1.854066605407503e-16, -5.2511356793649759e-30, -6.7993385117653912e-32,
> -1.5343740968067595e-18, -3.6785921616583949e-17, -0.0076700306438433133,
> 0.019231143599164325, 5.7818784939170702e-18, 1.7819897158350214e-17,
> -2.3927039320969442e-17, -3.9630951242056644e-18, 1.9779107704573469e-15,
> 7.8103367010164485e-15, -1.2351275675875924e-17, -8.6959160183013082e-15,
> -1.601002787863e-18, 3.0110116065267407e-19, 3.7155867714997651e-16,
> -0.12490087179942209, -2.2029631919898945e-16, -8.0869824211018481e-31,
> -5.058673986695e-33, 2.0667225433033359e-19, 1.0141735013231455e-18,
> 3.2845977347050714e-17, -2.9662734037779067e-19, 9.9595082331331027e-05,
> -1.9982466114987023e-18, 2.6420113469249318e-18, 5.2415327077690342e-19,
> 3.007533948014542e-18, -5.1128158961673558e-17, 6.7791246559883483e-19,
> -3.042327665547861e-15, 1.9523738271941284e-19, -4.0556768902105205e-20,
> -1.024372770865438e-17, -0.010638955366526863, 2.5786757042756338e-17,
> 1.3546130005558746e-32, 1.7947249868721723e-33, 1.9228405363682382e-19,
> -4.1209014001548407e-18, 1.5228291529275058e-17, 2.0443162438349059e-17,
> -1.9572693345249383e-18, 0.0012709581028842473, -0.0018515998737074948,
> 9.3128024867175073e-20, -5.1895788671618993e-17, 2.7373981615289174e-16,
> 1.2812977711597223e-17, -2.2792319486263267e-15, 4.1599503721278813e-19,
> -3.7733269771394201e-20, 4.16234419478765e-17, -1.5986158133468129e-16,
> -0.016037670900735834, -5.0763064708173244e-33, -1.0176066166236902e-50,
> -5.9296704797665404e-18, -8.0698801402861772e-17, 2.9646619457173492e-16,
> -2.8879431119718227

Re: [R] Problem with filling dataframe's column

2023-06-13 Thread Bill Dunlap
It is safer to use !grepl(...) instead of -grep(...) here.  If there are no
matches, the latter will give you a zero-row data.frame while the former
gives you the entire data.frame.

E.g.,

> d <- data.frame(a=c("one","two","three"), b=c(10,20,30))
> d[-grep("Q", d$a),]
[1] a b
<0 rows> (or 0-length row.names)
> d[!grepl("Q", d$a),]
  a  b
1   one 10
2   two 20
3 three 30

-Bill

On Tue, Jun 13, 2023 at 6:19 AM Rui Barradas  wrote:

> Às 17:18 de 13/06/2023, javad bayat escreveu:
> > Dear Rui;
> > Hi. I used your codes, but it seems it didn't work for me.
> >
> >> pat <- c("_esmdes|_Des Section|0")
> >> dim(data2)
> >  [1]  281549  9
> >> grep(pat, data2$Layer)
> >> dim(data2)
> >  [1]  281549  9
> >
> > What does grep function do? I expected the function to remove 3 rows of
> the
> > dataframe.
> > I do not know the reason.
> >
> >
> >
> >
> >
> >
> > On Mon, Jun 12, 2023 at 5:16 PM Rui Barradas 
> wrote:
> >
> >> Às 23:13 de 12/06/2023, javad bayat escreveu:
> >>> Dear Rui;
> >>> Many thanks for the email. I tried your codes and found that the length
> >> of
> >>> the "Values" and "Names" vectors must be equal, otherwise the results
> >> will
> >>> not be useful.
> >>> For some of the characters in the Layer column that I do not need to be
> >>> filled in the LU column, I used "NA".
> >>> But I need to delete some of the rows from the table as they are
> useless
> >>> for me. I tried this code to delete entire rows of the dataframe which
> >>> contained these three value in the Layer column: It gave me the
> following
> >>> error.
> >>>
> >>>> data3 = data2[-grep(c("_esmdes","_Des Section","0"), data2$Layer),]
> >>>Warning message:
> >>> In grep(c("_esmdes", "_Des Section", "0"), data2$Layer) :
> >>> argument 'pattern' has length > 1 and only the first element
> will
> >> be
> >>> used
> >>>
> >>>> data3 = data2[!grepl(c("_esmdes","_Des Section","0"), data2$Layer),]
> >>>   Warning message:
> >>>   In grepl(c("_esmdes", "_Des Section", "0"), data2$Layer) :
> >>>   argument 'pattern' has length > 1 and only the first element
> will be
> >>> used
> >>>
> >>> How can I do this?
> >>> Sincerely
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> On Sun, Jun 11, 2023 at 5:03 PM Rui Barradas 
> >> wrote:
> >>>
> >>>> Às 13:18 de 11/06/2023, Rui Barradas escreveu:
> >>>>> Às 22:54 de 11/06/2023, javad bayat escreveu:
> >>>>>> Dear Rui;
> >>>>>> Many thanks for your email. I used one of your codes,
> >>>>>> "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works
> >>>>>> correctly for me.
> >>>>>> Actually I need to expand the codes so as to consider all "Levels"
> in
> >>>> the
> >>>>>> "Layer" column. There are more than hundred levels in the Layer
> >> column.
> >>>>>> If I use your provided code, I have to write it hundred of time as
> >>>> below:
> >>>>>> data2$LU[which(data2$Layer == "Level 1")] <- "Park";
> >>>>>> data2$LU[which(data2$Layer == "Level 2")] <- "Agri";
> >>>>>> ...
> >>>>>> ...
> >>>>>> ...
> >>>>>> .
> >>>>>> Is there any other way to expand the code in order to consider all
> of
> >>>> the
> >>>>>> levels simultaneously? Like the below code:
> >>>>>> data2$LU[which(data2$Layer == c("Level 1","Level 2", "Level 3",
> ...))]
> >>>> <-
> >>>>>> c("Park", "Agri", "GS", ...)
> >>>>>>
> >>>>>>
> >>>>>> Sincerely
> >>>>

Re: [R] suprising behaviour of tryCatch()

2023-05-18 Thread Bill Dunlap
>  The only difference is the use of ’=’ or ‘<-‘ to assign the p value of
the fisher test to the vector.  I stopped using ‘<-‘ eons ago so it took a
bit to figure out.

The '=' has a context-dependent meaning - in a function call it is used to
name arguments and outside of a function call it is used for assignments.
This has nothing to do with tryCatch in particular.  E.g.,

> f <- function(x) x + 100
> f(y <- 10)
[1] 110
> y
[1] 10
> f(y = 20)
Error in f(y = 20) : unused argument (y = 20)
> y
[1] 10


I recommend starting to use <- for assignments again (or not doing
assignments inside of function calls).

-Bill

On Thu, May 18, 2023 at 7:38 AM Calboli Federico (LUKE) <
federico.calb...@luke.fi> wrote:

> Hello,
>
> I run a fisher.test() in a loop, with the issue that some of the data will
> not be useable. To protect the loop I used tryCatch but:
>
> sexsnp = rep(NA, 1750)
> for(i in 1:1750){tryCatch(sexsnp[i] = fisher.test(table(data[,3], data[,i
> + 38]))$p, error = function(e) print(NA))}
> Error: unexpected '=' in "for(i in 1:1750){tryCatch(sexsnp[i] ="
>
> But this works:
>
> for(i in 1:1750){tryCatch(sexsnp[i] <- fisher.test(table(data[,3], data[,i
> + 38]))$p, error = function(e) print(NA))}
> [1] NA
> [1] NA
> [1] NA
>
> The only difference is the use of ’=’ or ‘<-‘ to assign the p value of the
> fisher test to the vector.  I stopped using ‘<-‘ eons ago so it took a bit
> to figure out.
>
> Tested on R 4.1.2 on ContOS 8 , and on  R 4.3.0 on a M1 mac with the same
> result.  I’d be obliged if someone can explain why tryCatch assigns items
> with ‘<-‘ and not ‘=’.
>
> Cheers
>
> F
>
> Federico Calboli
> Tutkija
> Genomiikka ja jalostus
> Luonnonvarakeskus
>
> [[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 wind direction data with wind speed required

2023-05-13 Thread Bill Dunlap
I think that using complex numbers to represent the wind velocity makes
this simpler.  You would need to write some simple conversion functions
since wind directions are typically measured clockwise from north and the
argument of a complex number is measured counterclockwise from east.  E.g.,

windToComplex <-
function(speed, degreesCW) {
  complex(mod=speed, arg=(90-degreesCW)/180*pi)
}
complexToWind <-
function(z) {
  # Convert complex velocity z to speed and direction (degrees clockwise
  # from north, in range [0,360)).
  stopifnot(is.complex(z))
  data.frame(speed = Mod(z), degreesCW = (pi - Arg(z*1i))/(2*pi)*360)
}

Then use FUN=mean instead of my_fun.

-Bill

On Sat, May 13, 2023 at 7:51 AM Stefano Sofia <
stefano.so...@regione.marche.it> wrote:

> Dear list users,
>
> I have to aggregate wind direction data (wd) using a function that
> requires also a second input variable, wind speed (ws).
>
> This is the function that I need to use:
>
>
> my_fun <- function(wd1, ws1){
>
>   u_component <- -ws1*sin(2*pi*wd1/360)
>   v_component <- -ws1*cos(2*pi*wd1/360)
>   mean_u <- mean(u_component, na.rm=T)
>   mean_v <- mean(v_component, na.rm=T)
>   mean_wd <- (atan2(mean_u, mean_v) * 360/2/pi) + 180
>   result <- mean_wd
>   result
> }
>
> Does the aggregate function work only with functions with a single input
> variable (the one that I want to aggregate), or its use can be extended to
> functions with two input variables?
>
> Here a simple example (which is meaningless, the important think is the
> concept behind it):
> df <- data.frame(day=c(1, 1, 1, 2, 2, 2, 3, 3), month=c(1, 1, 2, 2, 2, 2,
> 2, 2), wd=c(45, 90, 90, 135, 180, 270, 270, 315), ws=c(7, 7, 8, 3, 2, 7,
> 14, 13))
>
> aggregate(wd ~ day + month, data=df, FUN = my_fun)
>
> cannot work, because ws is not taken into consideration.
>
> I got lost. Any hint, any help?
> I hope to have been able to explain my problem.
> Thank you for your attention,
> Stefano
>
>
>  (oo)
> --oOO--( )--OOo--
> Stefano Sofia PhD
> Civil Protection - Marche Region - Italy
> Meteo Section
> Snow Section
> Via del Colle Ameno 5
> 60126 Torrette di Ancona, Ancona (AN)
> Uff: +39 071 806 7743
> E-mail: stefano.so...@regione.marche.it
> ---Oo-oO
>
> 
>
> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere
> informazioni confidenziali, pertanto è destinato solo a persone autorizzate
> alla ricezione. I messaggi di posta elettronica per i client di Regione
> Marche possono contenere informazioni confidenziali e con privilegi legali.
> Se non si è il destinatario specificato, non leggere, copiare, inoltrare o
> archiviare questo messaggio. Se si è ricevuto questo messaggio per errore,
> inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio
> computer. Ai sensi dell'art. 6 della DGR n. 1394/2008 si segnala che, in
> caso di necessità ed urgenza, la risposta al presente messaggio di posta
> elettronica può essere visionata da persone estranee al destinatario.
> IMPORTANT NOTICE: This e-mail message is intended to be received only by
> persons entitled to receive the confidential information it may contain.
> E-mail messages to clients of Regione Marche may contain information that
> is confidential and legally privileged. Please do not read, copy, forward,
> or store this message unless you are an intended recipient of it. If you
> have received this message in error, please forward it to the sender and
> delete it completely from your computer system.
>
> --
> Questo messaggio  stato analizzato da Libraesva ESG ed  risultato non
> infetto.
> This message was scanned by Libraesva ESG and is believed to be clean.
>
>
> [[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] Regex Split?

2023-05-05 Thread Bill Dunlap
https://bugs.r-project.org/show_bug.cgi?id=16745 (from 2016, still labelled
'UNCONFIRMED") contains some other examples of strsplit misbehaving when
using 0-length perl look-behinds.  E.g.,

> strsplit(split="[[:<:]]", "One, two; three!", perl=TRUE)[[1]]
 [1] "O"  "n"  "e"  ", " "t"  "w"  "o"  "; " "t"  "h"  "r"  "e"  "e"  "!"
> gsub(pattern="[[:<:]]", "#", "One, two; three!", perl=TRUE)
[1] "#One, #two; #three!"

The bug report includes the comment

It may be possible that strsplit is not using the startoffset argument
to pcre_exec

  pcre/pcre/doc/html/pcreapi.html
A non-zero starting offset is useful when searching for another match
in the same subject by calling pcre_exec() again after a previous
success. Setting startoffset differs from just passing over a
shortened string and setting PCRE_NOTBOL in the case of a pattern that
begins with any kind of lookbehind.

or it could be something else.



On Fri, May 5, 2023 at 3:25 AM Ivan Krylov  wrote:

> On Thu, 4 May 2023 23:59:33 +0300
> Leonard Mada via R-help  wrote:
>
> > strsplit("a bc,def, adef ,,gh", " |(?=,)|(?<=,)(?![ ])", perl=T)
> > # "a""bc"   ",""def"  ",""" "adef" ",""," "gh"
> >
> > strsplit("a bc,def, adef ,,gh", " |(? > # "a""bc"   ",""def"  ",""" "adef" ",""," "gh"
> >
> > strsplit("a bc,def, adef ,,gh", " |(? > perl=T)
> > # "a""bc"   ",""def"  ",""" "adef" ",""," "gh"
> >
> >
> > Is this correct?
>
> Perl seems to return the results you expect:
>
> $ perl -E '
>  say("$_:\n ", join " ", map qq["$_"], split $_, q[a bc,def, adef ,,gh])
>  for (
>   qr[ |(?=,)|(?<=,)(?![ ])],
>   qr[ |(?   qr[ |(? )'
> (?^u: |(?=,)|(?<=,)(?![ ])):
>  "a" "bc" "," "def" "," "adef" "," "," "gh"
> (?^u: |(?  "a" "bc" "," "def" "," "adef" "," "," "gh"
> (?^u: |(?  "a" "bc" "," "def" "," "adef" "," "," "gh"
>
> The same thing happens when I ask R to replace the separators instead
> of splitting by them:
>
> sapply(setNames(nm = c(
>  " |(?=,)|(?<=,)(?![ ])",
>  " |(?  " |(? ), gsub, '[]', "a bc,def, adef ,,gh", perl = TRUE)
> #   |(?=,)|(?<=,)(?![ ]) |(? # "a[]bc[],[]def[],[]adef[],[],[]gh" "a[]bc[],[]def[],[]adef[],[],[]gh"
> #|(? # "a[]bc[],[]def[],[]adef[],[],[]gh"
>
> I think that something strange happens when the delimeter pattern
> matches more than once in the same place:
>
> gsub(
>  '(?=<--)|(?<=-->)', '[]', 'split here --><-- split here',
>  perl = TRUE
> )
> # [1] "split here -->[]<-- split here"
>
> (Both Perl's split() and s///g agree with R's gsub() here, although I
> would have accepted "split here -->[][]<-- split here" too.)
>
> On the other hand, the following doesn't look right:
>
> strsplit(
>  'split here --><-- split here', '(?=<--)|(?<=-->)',
>  perl = TRUE
> )
> # [[1]]
> # [1] "split here -->" "<"  "-- split here"
>
> The "<" is definitely not followed by "<--", and the rightmost "--" is
> definitely not preceded by "-->".
>
> Perhaps strsplit() incorrectly advances the match position after one
> match?
>
> --
> 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] DOUBT

2023-03-21 Thread Bill Dunlap
The HH Size is the problem - it doesn't follow R's rules for a name.  Put
backticks around it: `HH Size`.

-Bill

On Tue, Mar 21, 2023 at 9:47 AM Nandini raj 
wrote:

> Respected sir/madam
> can you please suggest what is an unexpected symbol in the below code for
> running a multinomial logistic regression
>
> model <- multinom(adoption ~ age + education + HH size + landholding +
> Farmincome + nonfarmincome + creditaccesibility + LHI, data=newdata)
>
> [[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] function doesn't exists but still runs.....

2023-01-19 Thread Bill Dunlap
Look into R's scoping rules.  E.g.,
https://bookdown.org/rdpeng/rprogdatascience/scoping-rules-of-r.html.

* When a function looks up a name, it looks it up in the environment in
which the function was defined.
* Functions in a package are generally defined in the package's environment
(although sometimes they are in a descendent of the parent's environment).
* When one searches an environment for a name, if it is not found in the
environment the search continues in the parent environment of that
environment, recursively until the parent environment is the empty
environment.

> with(environment(wdman::selenium), java_check)
function ()
{
javapath <- Sys.which("java")
if (identical(unname(javapath), "")) {
stop("PATH to JAVA not found. Please check JAVA is installed.")
}
javapath
}



-Bill

On Thu, Jan 19, 2023 at 2:28 PM akshay kulkarni 
wrote:

> dear members,
> I am using the RSelenium package which uses
> the function selenium() from the wdman package. The selenium function
> contains the function java_check at line 12. If I try to run it, it throws
> an error:
>
> >   javapath <- java_check()
> Error in java_check() : could not find function "java_check"
>
> Also:
>
> > exists("java_check")
> [1] FALSE
>
> But when I run selenium(), it works fine
>
> How do you explain this conundrum? You can refer to this link:
> https://github.com/ropensci/wdman/issues/15
>
> Specifically what concept of R explains this weird behaviour?
>
> Thanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
>
>
> [[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] Removing variables from data frame with a wile card

2023-01-14 Thread Bill Dunlap
The -grep(pattern,colnames) as a subscript is a bit dangerous.  If no
colname matches the pattern then all columns will be omitted (because -0 is
the same as 0, which means no column). !grepl(pattern,colnames) avoids this
problem.

> mydata <- data.frame(A=1:3,B=11:13)
> mydata[, -grep("^yr", colnames(mydata))]
data frame with 0 columns and 3 rows
> mydata[, !grepl("^yr", colnames(mydata))]
  A  B
1 1 11
2 2 12
3 3 13

-Bill

On Fri, Jan 13, 2023 at 11:07 PM Eric Berger  wrote:

> mydata[, -grep("^yr",colnames(mydata))]
>
> On Sat, Jan 14, 2023 at 8:57 AM Steven T. Yen  wrote:
>
> > I have a data frame containing variables "yr3",...,"yr28".
> >
> > How do I remove them with a wild cardsomething similar to "del yr*"
> > in Windows/doc? Thank you.
> >
> >  > colnames(mydata)
> >[1] "year"   "weight" "confeduc"   "confothr" "college"
> >[6] ...
> >   [41] "yr3""yr4""yr5""yr6" "yr7"
> >   [46] "yr8""yr9""yr10"   "yr11" "yr12"
> >   [51] "yr13"   "yr14"   "yr15"   "yr16" "yr17"
> >   [56] "yr18"   "yr19"   "yr20"   "yr21" "yr22"
> >   [61] "yr23"   "yr24"   "yr25"   "yr26" "yr27"
> >   [66] "yr28"...
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/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] return value of {....}

2023-01-13 Thread Bill Dunlap
R's
   { expr1; expr2; expr3}
acts much like C's
   ( expr1, expr2, expr3)

E.g.,

$ cat a.c
#include 

int main(int argc, char* argv[])
{
double y = 10 ;
double x = (printf("Starting... "), y = y + 100, y * 20);
printf("Done: x=%g, y=%g\n", x, y);
return 0;
}
$ gcc -Wall a.c
$ ./a.out
Starting... Done: x=2200, y=110

I don't like that syntax (e.g., commas between expressions instead of the
usual semicolons after expressions).  Perhaps John Chambers et all didn't
either.

-Bill

On Fri, Jan 13, 2023 at 2:28 AM Valentin Petzel  wrote:

> Hello Akshay,
>
> R is quite inspired by LISP, where this is a common thing. It is not in
> fact that {...} returned something, rather any expression evalulates to
> some value, and for a compound statement that is the last evaluated
> expression.
>
> {...} might be seen as similar to LISPs (begin ...).
>
> Now this is a very different thing compared to {...} in something like C,
> even if it looks or behaves similarly. But in R {...} is in fact an
> expression and thus has evaluate to some value. This also comes with some
> nice benefits.
>
> You do not need to use {...} for anything that is a single statement. But
> you can in each possible place use {...} to turn multiple statements into
> one.
>
> Now think about a statement like this
>
> f <- function(n) {
> x <- runif(n)
> x**2
> }
>
> Then we can do
>
> y <- f(10)
>
> Now, you suggested way would look like this:
>
> f <- function(n) {
> x <- runif(n)
> y <- x**2
> }
>
> And we'd need to do something like:
>
> f(10)
> y <- somehow_get_last_env_of_f$y
>
> So having a compound statement evaluate to a value clearly has a benefit.
>
> Best Regards,
> Valentin
>
> 09.01.2023 18:05:58 akshay kulkarni :
>
> > Dear Valentin,
> >   But why should {} "return" a value? It
> could just as well evaluate all the expressions and store the resulting
> objects in whatever environment the interpreter chooses, and then it would
> be left to the user to manipulate any object he chooses. Don't you think
> returning the last, or any value, is redundant? We are living in the
> 21st century world, and the R-core team might,I suppose, have a definite
> reason for"returning" the last value. Any comments?
> >
> > Thanking you,
> > Yours sincerely,
> > AKSHAY M KULKARNI
> >
> > 
> > *From:* Valentin Petzel 
> > *Sent:* Monday, January 9, 2023 9:18 PM
> > *To:* akshay kulkarni 
> > *Cc:* R help Mailing list 
> > *Subject:* Re: [R] return value of {}
> >
> > Hello Akshai,
> >
> > I think you are confusing {...} with local({...}). This one will
> evaluate the expression in a separate environment, returning the last
> expression.
> >
> > {...} simply evaluates multiple expressions as one and returns the
> result of the last line, but it still evaluates each expression.
> >
> > Assignment returns the assigned value, so we can chain assignments like
> this
> >
> > a <- 1 + (b <- 2)
> >
> > conveniently.
> >
> > So when is {...} useful? Well, anyplace where you want to execute
> complex stuff in a function argument. E.g. you might do:
> >
> > data %>% group_by(x) %>% summarise(y = {if(x[1] > 10) sum(y) else
> mean(y)})
> >
> > Regards,
> > Valentin Petzel
> >
> > 09.01.2023 15:47:53 akshay kulkarni :
> >
> >> Dear members,
> >>  I have the following code:
> >>
> >>> TB <- {x <- 3;y <- 5}
> >>> TB
> >> [1] 5
> >>
> >> It is consistent with the documentation: For {, the result of the last
> expression evaluated. This has the visibility of the last evaluation.
> >>
> >> But both x AND y are created, but the "return value" is y. How can this
> be advantageous for solving practical problems? Specifically, consider the
> following code:
> >>
> >> F <- function(X) {  expr; expr2; { expr5; expr7}; expr8;expr10}
> >>
> >> Both expr5 and expr7 are created, and are accessible by the code
> outside of the nested braces right? But the "return value" of the nested
> braces is expr7. So doesn't this mean that only expr7 should be accessible?
> Please help me entangle this (of course the return value of F is expr10,
> and all the other objects created by the preceding expressions are deleted.
> But expr5 is not, after the control passes outside of the nested braces!)
> >

Re: [R] extract from a list of lists

2022-12-27 Thread Bill Dunlap
I find your original sapply(List, function(element)element$name) easy to
understand.  However replacing sapply with vapply makes for more robust
code.  vapply requires you to supply the expected mode (type) and length of
element$name and if any of the elements don't comply with that, vapply
gives an error (sapply returns a list in this case).  Also, for lists of
length zero, it returns a 0-long result of the mode you specified (instead
of sapply's list()).  In the usual happy case it returns what sapply does.
 It happens to be a bit faster than sapply and uses less memory, but I
think the checks that it does make it worth using instead of sapply.

E.g.,
> L <- list(list(A=1, B=c(TRUE,FALSE)), list(A=2, B=c(FALSE,FALSE)),
list(A=3))
> vapply(L, function(el)el$A, FUN.VALUE=numeric(1))
[1] 1 2 3
> vapply(L, function(el)el$B, FUN.VALUE=logical(2))
Error in vapply(L, function(el) el$B, FUN.VALUE = logical(2)) :
  values must be length 2,
 but FUN(X[[3]]) result is length 0
> vapply(L, function(el){ z <- el$B; if (is.null(z)) rep(NA,2) else z},
FUN.VALUE=logical(2))
  [,1]  [,2] [,3]
[1,]  TRUE FALSE   NA
[2,] FALSE FALSE   NA

-Bill

On Tue, Dec 27, 2022 at 1:10 PM Therneau, Terry M., Ph.D. via R-help <
r-help@r-project.org> wrote:

> Thanks everyone for prodding my gray matter, which seems to be getting
> stiffer as I
> approach 70 (< 90 days).
>
>   --  I'll continue to use the $ or [[ forms.   That will suffice.
>
> --  I thought there might be a base R variant, e.g. something like
> extract( list,
> element-name); probably cross talk in my brain from the rstan library
>
> -- Gregg's note shows such a function in purr.  But I rather like having
> as few
> dependencies as possible in a package, one usage is normally not enough,
> at least for
> something this simple.
>
> Terry T.
>
> On 12/27/22 14:38, Bert Gunter wrote:
> > Well, I prefer Greg's approach, but if you want to avoid calls to $ or
> > `[[` then you could do:
> >
> > unlist(fits)[ rep(names(fits[[1]]) == 'iter', length(fits))]
> >
> >
> > Cheers,
> > Bert
> >
> > On Tue, Dec 27, 2022 at 9:46 AM Greg Snow<538...@gmail.com>  wrote:
> >> Another option is the map family of functions in the purrr package
> >> (yes, this depends on another package being loaded, which may affect
> >> things if you are including this in your own package, creating a
> >> dependency).
> >>
> >> In map and friends, if the "function" is a string or integer, then it
> >> is taken as the piece to be extracted, so you should be able to do
> >> something like:
> >>
> >> library(purrr)
> >> map(fits, 'iter')
> >> # or
> >> map_int(fits, 'iter')
> >> # or
> >> map_dbl(fits, 'iter')
> >>
> >> which of the last 2 to use depends on how `iter` is stored.
> >>
> >> On Tue, Dec 27, 2022 at 10:16 AM Therneau, Terry M., Ph.D. via R-help
> >>   wrote:
> >>> I not uncommonly have the following paradym
> >>>  fits <- lapply(argument, function)
> >>>
> >>> resulting in a list of function results.   Often, the outer call is to
> mclapply, and the
> >>> function encodes some long calculation, e.g. multiple chains in an
> MCMC.
> >>> Assume for illustration that each function returns a list with
> elements   beta, loglik,  iter.
> >>>
> >>> Then  sapply(fits,  function(x) x$iter)
> >>> will give me a vector, with the number of iterations used by each
> instance.
> >>>
> >>> I've often been suspicious that there is some simple shorthand for the
> "grab all the
> >>> elements named iter" that skips the explicit x$iter function.   Am I
> indeed overlooking
> >>> something?I don't expect a speed increase, just cleaner code.
> >>>
> >>> Terry T.
> >>>
> >>> --
> >>> Terry M Therneau, PhD
> >>> Department of Quantitative Health Sciences
> >>> Mayo Clinic
> >>> thern...@mayo.edu
> >>>
> >>> "TERR-ree THUR-noh"
> >>>
> >>>  [[alternative HTML version deleted]]
> >>>
> >>> __
> >>> R-help@r-project.org  mailing list -- To UNSUBSCRIBE and more, see
> >>>
> https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctherneau%40mayo.edu%7Cebbda887f4b94223376608dae84a58ae%7Ca25fff9

Re: [R] Error 3221226505

2022-12-18 Thread Bill Dunlap
Note that 3221226505 in base 10 is C409 in hexadecimal.  You may have
better luck looking for causes of this by googling the hex representation.

-Bill

On Sun, Dec 18, 2022 at 3:56 PM Mathurin, Gottfried via R-help <
r-help@r-project.org> wrote:

> Hello,
> I currently face the issue of Windows 10 throwing a code 3221226505
> whenever I try to use R-4.1.3.
> Is this issue known and could you possibly share a fix?
>
> Thank you in advance,
>
> *Gottfried*
>
> --
>
>
> This
>
> e-mail transmission (message and any attached files) may contain
> information that is proprietary, privileged and/or confidential to Veolia
> Environnement and/or its affiliates and is intended exclusively for the
> person(s) to whom it is addressed. If you are not the intended recipient,
> please notify the sender by return e-mail and delete all copies of this
> e-mail, including all attachments. Unless expressly authorized, any use,
> disclosure, publication, retransmission or dissemination of this e-mail
> and/or of its attachments is strictly prohibited.
>
>
> Ce message
> electronique et ses fichiers attaches sont strictement confidentiels et
> peuvent contenir des elements dont Veolia Environnement et/ou l'une de ses
> entites affiliees sont proprietaires. Ils sont donc destines a l'usage de
> leurs seuls destinataires. Si vous avez recu ce message par erreur, merci
> de le retourner a son emetteur et de le detruire ainsi que toutes les
> pieces attachees. L'utilisation, la divulgation, la publication, la
> distribution, ou la reproduction non expressement autorisees de ce message
> et de ses pieces attachees sont interdites.
>
> 
>
> [[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] is.na()<- on a character vector

2022-12-16 Thread Bill Dunlap
I think that
   is.na(x) <- i
generally does the same to x as does
   x[i] <- NA

I say 'generally' because some classes (e.g., numeric_version) do not allow
x[i]<-NA but do allow is.na(x)<-i.  It is possible that some classes mess
up this equivalence, but I think that would be considered a bug.

-Bill

On Fri, Dec 16, 2022 at 10:29 AM Göran Broström 
wrote:

> I'm confused:
>
> > x <- 1:2
> > is.na(x) <- 1
> > x
> [1] NA  2
>
> OK, but
>
> > x <- c("A", "B")
> > is.na(x) <- "A"
> > x
>A
> "A" "B"  NA
>
> What happens?
>
> G_ran
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] Logistic regression for large data

2022-11-14 Thread Bill Dunlap
summary(Base)

would show if one of columns of Base was read as character data instead of
the expected numeric.  That could cause an explosion in the number of dummy
variables, hence a huge design matrix.

-Bill


On Fri, Nov 11, 2022 at 11:30 PM George Brida 
wrote:

> Dear R users,
>
> I have a database  called Base.csv   (attached to this email) which
> contains 13 columns and 8257 rows and whose the first 8 columns are dummy
> variables which take 1 or 0. The problem is when I wrote the following
> instructions to do a logistic regression , R runs for hours and hours
> without giving an output:
>
> Base=read.csv("C:\\Users\\HP\\Desktop\\New\\Base.csv",header=FALSE,sep=";")
>
> fit_1=glm(Base[,2]~Base[,1]+Base[,10]+Base[,11]+Base[,12]+Base[,13],family=binomial(link="logit"))
>
> Apparently, there is not enough memory to have the requested output. Is
> there any other function for logistic regression that handle large data and
> return output in reasonable time.
>
> Many thanks
>
> Kind regards
>
> George
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] Replace multiple subexpressions at once?

2022-10-25 Thread Bill Dunlap
There probably is a package with such a function, but you can do with one
call to sub() if you parenthesize all the subexpressions in the regular
expression and use \\1, etc., in the replacement for those parts you want
to keep.  E.g.,

> s <- ""
> want <-  ""
> new_regexp <- "(.*<[^>]+ data-pos=\")([^\"]*)(@)([[:digit:]]+)(:.*)"
> all.equal( sub(new_regexp, "\\1newname\\3newnumber\\5", s), want)
[1] TRUE

-Bill


On Tue, Oct 25, 2022 at 10:12 AM Duncan Murdoch 
wrote:

> An R regular expression pattern can contain parenthesized
> subexpressions, and those can be used later in the same pattern, or in
> the replacement in sub() and gsub().  What I'd like to do is match
> several subexpressions and replace all of them.
>
> For example, I might have a string like
>
>  s <- ""
>
> and I can use the regular expression
>
>  regexp <- ".*<[^>]+ data-pos=\"([^\"]*)@([[:digit:]]+):.*"
>
> to match the whole thing, with \\1 matching "Untitled.knit.md" and \\2
> matching "12".  I'd like to replace the first with "newname" and the
> second with "newnumber", so the string ends up looking like
>
>  s <- ""
>
> I could write a function to do this using regexec() and two calls to
> `substring<-`(), but I'm hoping someone has already done that.  Any
> suggestions?
>
> Duncan Murdoch
>
> P.S.  I'm going to be travelling for a couple of weeks, and so may not
> respond right away.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] cat in a subroutine

2022-10-13 Thread Bill Dunlap
Do you have another function called "cat" in scope? (with an argument
called "j")?  Before calling cat("...") call print(cat) and
print(find("cat")).

-Bill


On Thu, Oct 13, 2022 at 12:35 AM Steven T. Yen  wrote:

> I have had an issue with printing (with cat) in a subroutine for which I
> do not have a applicable example, but I am still hoping to get some
> help. In the following, the first block of code works fine.
>
> ...
>
> t<-abs(me)/se; p<-2*(1-pt(t,nrow(x)))
> sig<-my.sig.levels(p)
> out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,sig)
> rownames(out)<-names(me)
> colnames(out)<-c("est","se","t","p","sig")
> j<-grep(".one\\b",rownames(out))
> out<-out[-j,]
> return(out)
> }
>
> But as soon as I insert lines to print (cat) soething simple, it spits
> out message that appears to be nonsence (unrelated). Any idea. Please
> help. Thanks.
>
> t<-abs(me)/se; p<-2*(1-pt(t,nrow(x)))
> sig<-my.sig.levels(p)
> out<-data.frame(round(cbind(me,se,t,p),digits)); out<-cbind(out,sig)
> rownames(out)<-names(me)
> colnames(out)<-c("est","se","t","p","sig")
> cat("\nMarginal and Discrete Effects of Gen Ordered Logit / Probit
> Probabilities",
>  "\n\nlogistic =",logistic)
> j<-grep(".one\\b",rownames(out))
> out<-out[-j,]
> return(out)
> }
>
> In this particular case, the error message was as follows:
>
> Error in cat("\nMarginal and Discrete Effects of Gen Ordered Logit /
> Probit Probabilities",  :
>unused argument (logistic)
>
> I have printed this way in numerous routines without problem and do not
> see why this is happending.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] Getting "Error in ect, plot.new has not been called yet" despite grouping plot call

2022-10-06 Thread Bill Dunlap
Here is how you could have made an example that helpers could easily run.
It also includes the fix.

f <- function(print.it = FALSE) {
   pdf(file.pdf <- tempfile(fileext=".pdf"))
   series <- as.xts(setNames(sin(seq(0,10,by=.1)),
seq(as.Date("2022-10-06"),by="weeks",len=101)))
   p <- plot(series)
   if (print.it) {
   print(p)
   }
   sm_series_2 <- smooth(series / 2)
   lines(sm_series_2, col="red")
   abline(h=0.1, col="blue")
   dev.off()
   file.pdf
}
> f()
Error in plot.xy(xy.coords(x, y), type = type, ...) :
  plot.new has not been called yet
> f(TRUE)
[1]
"C:\\Users\\willi\\AppData\\Local\\Temp\\Rtmp0wX7rO\\file34843df652c.pdf"

If you remove the pdf() and dev.off() I think you will see that the added
lines do not show up.  I think plot.xts fiddles with the coordinate system
before and after it plots so that add-ons must be done in a special way.

-Bill

On Thu, Oct 6, 2022 at 12:42 AM Deramus, Thomas Patrick <
tdera...@partners.org> wrote:

> Hi Rolf.
>
> I followed your suggestion (though it's probably not as trimmed as it
> could be), but the problem unfortunately persists.
>
> Does this make it any clearer or still too many moving parts to make sense
> of?
>
> rm(list = ls(all.names = TRUE)) #will clear all objects includes hidden
> objects.
>
> #Loads the packages
> library(plyr)
> library(dplyr)
> library(ggplot2)
> library(Kendall)
> library(lubridate)
> library(xts)
> library(TTR)
> library(trend)
> library(forecast)
> library(openxlsx)
>
> #Uses the learningCurve Package from Github:
> #https://github.com/AFIT-R/learningCurve
> library(learningCurve)
>
> #Only load this if using VS Studio because it changes the plot function
> #
> https://stackoverflow.com/questions/52284345/how-to-show-r-graph-from-visual-studio-code
> library(httpgd)
> library(languageserver)
>
> #Loads the Excel files to Dataframes and cleans the data
> Game_Metrics_Word_Task <-
> read.xlsx("GamePack_Analytics_ALL_TIME_Short.xlsx", "Boggle")
> Game_Metrics_Word_Task <- Game_Metrics_Word_Task %>% filter(grepl('1440',
> StudyId))
> Game_Metrics_Word_Task$DeviceTime <-
> ymd_hms(Game_Metrics_Word_Task$DeviceTime,  tz = "America/New_York")
> Game_Metrics_Word_Task <-
> Game_Metrics_Word_Task[!duplicated(Game_Metrics_Word_Task[1:2,])]
>
> #Splits the dataframe into a tibble containing each participant
> Participant_Word_Task <-
> split(arrange(Game_Metrics_Word_Task,StudyId,DeviceTime),
> arrange(Game_Metrics_Word_Task,StudyId,DeviceTime,StudyId,DeviceTime)$StudyId)
>
> #Generates a blank output dataframe
> WordFrame <- data.frame(Participant = c(0), Task = c(0), MannKendall_Tau =
> c(0), MannKendall_P = c(0), Sen_Slope_Value = c(0), Sen_Slope_Pval = c(0),
> Pettitts_CIV = c(0), Pettitts_Pval = c(0), ARIMA_Model = c(0),
> Time_to_Petit = c(0), Number_of_Trials_to_Pettitt = c(0),
> Playtime_to_Petit_seconds = c(0), Time_Start_to_end_days = c(0),
> Number_of_Total_Trials = c(0), Total_Playtime_seconds = c(0),
> Learning_rate_days = c(0), Learning_rate_seconds = c(0), Learned_Task =
> c(0))
>
> #The number of subjects in the xlsx file
> #Reduced to 2 for ease of use
> for (i in 1:2){
>   #This timeseries only includes the trials where the participant
> completed the task
>   success_series <- xts(filter(Participant_Word_Task[[i]], GameEndReason
> == "TIMER_UP")$NumberOfSuccesfulWords , 
> order.by=as.POSIXct(filter(Participant_Word_Task[[i]],
> GameEndReason == "TIMER_UP")$DeviceTime))
>   #This timeseries includes ALL the trials for the sake of plotting
>   original_series <-
> xts(Participant_Word_Task[[i]]$NumberOfSuccesfulWords, order.by
> =as.POSIXct(Participant_Word_Task[[i]]$DeviceTime))
>
>   #This is a decomposing process that xts seems to need for plotting.
>   #nweeks is needed for xts to plot the x-axis
>   success_decomp <- ts(success_series, frequency = nweeks(success_series))
>   original_decomp <- ts(original_series, frequency =
> nweeks(success_series))
>
>   #Values which will be included in the plots
>   WordFrame[i,1] <- unique(Participant_Word_Task[[i]]$StudyId)
>   WordFrame[i,5] <- sens.slope(success_decomp)$estimates
>   WordFrame[i,6] <- sens.slope(success_decomp)$p.value
>   WordFrame[i,7] <- pettitt.test(success_decomp)$estimate
>   WordFrame[i,8] <- pettitt.test(success_decomp)$p.value
>
>   #The simple moving average that will be overlayed with the plotted data
>   simplemovingaverage <- SMA(original_series, n = nweeks(original_series))
>
>   #If the three tests are statistically significant, add a green
> horizontal like to v

Re: [R] How to find the variance-covariance matrix of a random-vector using R

2022-09-20 Thread Bill Dunlap
?var

E.g.,

> x <- mvtnorm::rmvnorm(1e5, mean=101:105, sigma=matrix(1,5,5)+diag(11:15))
> dim(x)
[1] 10  5
> var(x)
   [,1]   [,2]   [,3]   [,4]  [,5]
[1,] 11.9666055  1.0603876  0.9627672  1.0371084  0.983217
[2,]  1.0603876 13.0774518  1.0228972  0.9261868  1.059799
[3,]  0.9627672  1.0228972 13.9296063  1.0444007  1.051089
[4,]  1.0371084  0.9261868  1.0444007 15.1556199  1.052573
[5,]  0.9832170  1.0597985  1.0510888  1.0525734 15.965351

-Bill

On Tue, Sep 20, 2022 at 4:24 AM Sun, John  wrote:

> Dear All,
> Reposting as plain text rather than html.
>
> I realized that R does not support finding the variance-covariance matrix
> of a random-vector. It must take two arguments. Numpy's cov doesn't give
> sensible results.
> I ask in a bigger context of finding the variance-covariance matrix of the
> vector of the dependent variables per subject which is the covariance form
> of the working-correlation matrix in GEE by Liang-Zeger (1986). Knowing it
> gives me better inference via efficiency improvement.
>
> I have not received a reply on these posts, so I ask.
>
> https://stats.stackexchange.com/questions/589022/how-to-find-covy-i-using-software-in-the-context-sum-i-1-mathrmk
>
> https://stackoverflow.com/questions/73755242/is-there-a-r-function-or-python-for-finding-the-covariance-matrix-of-a-random-ve
>
> Best regards,
> Kpjm
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] inconsistency in switch statements.....

2022-09-08 Thread Bill Dunlap
The same is true for any function call; switch() is not special in this
regard.

> f <- function(x, ...) list(...)
> f("x"=1, "2"=2, `3`=3)
$`2`
[1] 2

$`3`
[1] 3

The backticks are required when defining a function with a non-syntactical
name, but the call can use either form.

> f <- function(x, `2`) x - `2`
> f("2"=7, 18)
[1] 11
> f(`2`=7, 18)
[1] 11


-Bill

On Wed, Sep 7, 2022 at 11:41 PM Richard O'Keefe  wrote:

> You DON'T need to use backticks.  switch() is much older than backticks.
> Ordinary quotation marks are fine.
> > switch(as.character(1), "2"="YES", "1"="NO")
> [1] "NO"
>
>
> On Thu, 8 Sept 2022 at 07:46, akshay kulkarni 
> wrote:
>
> > Dear Bert,
> > Thanks...I went through the doc pages but couldn't
> > glean from that that for numeric options one has to backtick it. I is not
> > given in the doc page...I actually had hundreds of different choices and
> so
> > cannot depend on evaluation by position...Thanks again...I got to know
> that
> > 2 is not a valid identifier but`2` is!
> >
> > Yours sincerely,
> > AKSHAY M KULKARNI
> >
> > 
> > From: Bert Gunter 
> > Sent: Thursday, September 8, 2022 12:39 AM
> > To: akshay kulkarni 
> > Cc: R help Mailing list 
> > Subject: Re: [R] inconsistency in switch statements.
> >
> > Well, as it states on the Help page, which should always be the first
> > place to look for, ummm, help:
> >
> > "If the value of EXPR is not a character string it is coerced to
> > integer. Note that this also happens for factors, with a warning, as
> > typically the character level is meant. If the integer is between 1
> > and nargs()-1 then the corresponding element of ... is evaluated and
> > the result returned: thus if the first argument is 3 then the fourth
> > argument is evaluated and returned."
> >
> > So following up on Bill's comment, the arguments do not even need to
> > be names when Stst evaluates to) an integer:
> >
> > > Stst <- 2
> > > switch(Stst, print("NO"), print("YES"))
> > [1] "YES"
> >
> > Cheers,
> > Bert
> >
> > On Wed, Sep 7, 2022 at 11:35 AM akshay kulkarni 
> > wrote:
> > >
> > > Dear members,
> > >  The following is my code:
> > >
> > > > Stst <- 2
> > > > switch(Stst, 1 = print("NO"), 2 = print("YES"))
> > > Error: unexpected '=' in "switch(Stst, 1 ="
> > >
> > > Why isn't it printing "YES" on to the console?
> > >
> > > many thanks in advance.
> > >
> > > Thanking you,
> > > Yours sincerely,
> > > AKSHAY M KULKARNI
> > >
> > > [[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.
>

[[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] Getting minimum value of a column according a factor column of a dataframe

2022-08-25 Thread Bill Dunlap
The order of the rows returned by summarize is controlled by the levels of
the factors given to group_by.  If group_by is given character columns
instead of factors, it converts them to factors with the levels being the
sorted unique values of the character columns.  Convert you character
columns to factors with the desired levels to get the order you want.

E.g.,

> d <- data.frame(charGroup=rep(c("Small","Medium","Large"),3:1), x=101:106)
> d$factorGroup <- factor(d$charGroup, levels=c("Small","Medium","Large","X
Large"))
> d
  charGroup   x factorGroup
1 Small 101   Small
2 Small 102   Small
3 Small 103   Small
4Medium 104  Medium
5Medium 105  Medium
6 Large 106   Large
> d |> group_by(charGroup) |> summarize(minX=min(x))
# A tibble: 3 × 2
  charGroup  minX
   
1 Large   106
2 Medium  104
3 Small   101
> d |> group_by(factorGroup) |> summarize(minX=min(x))
# A tibble: 3 × 2
  factorGroup  minX
 
1 Small 101
2 Medium104
3 Large 106
> # .drop=FALSE outputs a row for each unused level as well
> d |> group_by(factorGroup, .drop=FALSE) |> summarize(minX=min(x))
# A tibble: 4 × 2
  factorGroup  minX
 
1 Small 101
2 Medium104
3 Large 106
4 X Large   Inf
Warning message:
In min(x) : no non-missing arguments to min; returning Inf

-Bill

On Thu, Aug 25, 2022 at 4:05 AM javad bayat  wrote:

> Dear Rui;
> Thank you very much. Both of your codes worked correctly. Now I can see the
> whole row's value.
> But I found a problem in the results. When I run your codes, the results
> are shown in a sorted table. I do not know why the results have been sorted
> according to the "Code" column, smallest to largest. Is there any way to
> get the results like their order in the first data frame (bilan2)? I used
> your codes as follow:
>
> > bilan3 <- lapply(split(bilan2, bilan2$Code), \(x) x[which.min(x$Q),])
> > bilan3 = data.frame(do.call(rbind, bilan3))
> Sincerely
>
>
>
> On Thu, Aug 25, 2022 at 11:52 AM Rui Barradas 
> wrote:
>
> > Hello,
> >
> > OK, what about
> >
> >
> > res <- lapply(split(df1, df1$Code), \(x) x[which.min(x$Q),])
> > do.call(rbind, res)
> > # Code  Y  M  D QNO
> > #  41003 41003 81  1 19 0.160 7.17 2.50
> > #  41005 41005 79  8 17 0.210 5.50 7.20
> > #  41009 41009 79  2 21 0.218 5.56 4.04
> > #  41017 41017 79 10 20 0.240 5.30 7.10
> >
> >
> > A dplyr solution.
> >
> >
> >
> > suppressPackageStartupMessages(library(dplyr))
> >
> > df1 %>%
> >group_by(Code) %>%
> >slice_min(Q) %>%
> >slice_head(n = 1)
> > #  # A tibble: 4 × 7
> > #  # Groups:   Code [4]
> > #Code  Y M D Q N O
> > #  
> > #  1 4100381 119 0.16   7.17  2.5
> > #  2 4100579 817 0.21   5.5   7.2
> > #  3 4100979 221 0.218  5.56  4.04
> > #  4 41017791020 0.24   5.3   7.1
> >
> >
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> >
> > Às 05:56 de 25/08/2022, javad bayat escreveu:
> > > Dear all,
> > > Many thanks for your suggested methods and codes, but unfortunately
> they
> > > did not give the desired results.
> > > All the codes you have provided are correct but they did not represent
> > the
> > > whole row which is related to the minimum of "Q".
> > > The code must result in 4 rows, with the minimum value of "Q" and other
> > > column values, as below:
> > >
> > > Code
> > >
> > >Y
> > >
> > >M
> > >
> > > D
> > >
> > > Q
> > >
> > >  N
> > >
> > >   O
> > >
> > > 41003
> > >
> > > 81
> > >
> > > 1
> > >
> > > 19
> > >
> > > 0.16
> > >
> > > 7.17
> > >
> > > 2.5
> > >
> > > 41005
> > >
> > > 79
> > >
> > > 8
> > >
> > > 17
> > >
> > > 0.21
> > >
> > > 5.5
> > >
> > > 7.2
> > >
> > > 41009
> > >
> > > 79
> > >
> > > 2
> > >
> > > 21
> > >
> > > 0.218
> > >
> > > 5.56
> > >
>

Re: [R] Error generated by nlme::gnls

2022-07-24 Thread Bill Dunlap
I think the intent of this code was to see if the formula had solely a
literal 1 on the right hand side.
Then !identical(pp[[3]], 1) would do it, avoiding the overhead of calling
deparse.  Note that the
1 might be an integer, which the current code would (erroneously) not
catch, so
   !identical(pp[[3]], 1) && !identical(pp[[3]], 1L)
or something equivalent would be better.

-Bill

On Sun, Jul 24, 2022 at 5:58 AM Ivan Krylov  wrote:

> Sorry for being too terse in my previous e-mail!
>
> On Sun, 24 Jul 2022 23:03:02 +1200
> Rolf Turner  wrote:
>
> > The maintainer of the nlme package (who is, according to maintainer(),
> > "R-core") could change the code so that it uses invokes deparse1()
> > rather than deparse, but the user cannot do so, not without in effect
> > re-creating the package.
>
> You're right. I think there's a buglet in nlme::gnls that nobody
> noticed until R 4.2.0 was released *and* Aaron Crowley used the
> function with a sufficiently long formula.
>
> > Also, the question remains:  why did Aaron Crowley's code work in the
> > past, whereas now it throws an error?  What changed?
>
> gnls() may have been performing the `if (deparse(...) != '1')` test for
> a long time, but never crashed before because it wasn't a fatal error
> until R 4.2.0. Previously, if() would issue a warning and use the first
> element of the boolean vector.
>
> R 4.2.0 was released this April, which was less than 6 months ago. I
> think it all fits.
>
> A temporary solution would be to make use of the fact that R is a very
> dynamic language and perform surgery on a live function inside a loaded
> package:
>
> library(codetools)
>
> nlme <- loadNamespace('nlme')
> unlockBinding('gnls', nlme)
> nlme$gnls <- `body<-`(fun = nlme$gnls, value = walkCode(
> body(nlme$gnls), makeCodeWalker(
> call = function(e, w)
> as.call(lapply(as.list(e), function(ee)
> if (!missing(ee)) walkCode(ee, w)
> )),
> leaf = function(e, w)
> if (is.symbol(e) && e == 'deparse') {
> as.name('deparse1')
> } else e
> )
> ))
> lockBinding('gnls', nlme)
> rm(nlme)
>
> grep('deparse', deparse(nlme::gnls), value = TRUE)
> # [1] "deparse1(pp[[3]]), sep = \"~\"), collapse =
> \",\"), " # [2] "if (deparse1(params[[nm]][[3]]) != \"1\") {"
> # [3] "list(row.names(dataModShrunk), deparse1(form[[2]]))), "
>
> Aaron's example seems to work after this, modulo needing 12 starting
> values instead of 13.
>
> --
> 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] aborting the execution of a function...

2022-07-13 Thread Bill Dunlap
You could write a function that returns an environment (or list if you
prefer) containing the results collected before the interrupt by using
tryCatch(interrupt=...).  E.g.,

doMany <- function(names) {
resultEnv <- new.env(parent=emptyenv())
tryCatch(
for(name in names) resultEnv[[name]] <- Sys.sleep(1), # replace
Sys.sleep(1) by getStuffFromWeb(name)
interrupt = function(e) NULL)
resultEnv
}

Use it as

> system.time(e <- doMany(state.name)) # hit Esc or ^C after a few seconds
^C   user  system elapsed
  0.001   0.000   4.390
> names(e)
[1] "Alabama"  "Alaska"   "Arizona"  "Arkansas"
> eapply(e, identity)
$Alabama
NULL

$Alaska
NULL

$Arizona
NULL

$Arkansas
NULL

-Bill

On Wed, Jul 13, 2022 at 12:20 PM akshay kulkarni 
wrote:

> Dear members,
>  I am running a large scraping code in a very
> powerful AWS ec2 instance:
>
> DATES <- getFirms Dates()
>
> It iterates over 500 stocks from a website. Despite the power of the
> machine, the execution is very slow.
>
> If I abort the function (by ctrl + C), after, say 150th iteration, the
> DATES object will still contain the scraped data untill the 150th
> iteration, right? ( The rest of the 350 entries will be NA's, I suppose).
>
> Many thanks in advance.
>
> Yours sincerely,
> AKSHAY M KULKARNI
>
>
>
> [[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] Is it possible to set a default working directory for all R consoles?

2022-06-17 Thread Bill Dunlap
Is there an environment variable containing that IP address?

 as.list(grep(value=TRUE, "172", Sys.getenv())) # as.list to make
printing nicer

If you know which variable is causing the problem you may be able to
override it by setting an R-specific one.

-Bill

On Fri, Jun 17, 2022 at 8:28 AM IAGO GINÉ VÁZQUEZ  wrote:

> Hi all,
>
> Is there some way to set a default working directory each time R.exe is
> opened? I ask this because Always that I open R 4.2.o in Windows 10 I get
> the next warning messages
>
> Warning message:
> In normalizePath(path.expand(path), winslash, mustWork) :
>   path[1]="\\172.19.2.44\profiles\profiles\me\Documents": Access is denied
> Warning message:
> In normalizePath(path.expand(path), winslash, mustWork) :
>   path[1]="\\172.19.2.44\profiles\profiles\me\Documents": Access is denied
> Warning message:
> In normalizePath(path.expand(path), winslash, mustWork) :
>   path[1]="\\172.19.2.44\profiles\profiles\me\Documents": Access is denied
> Warning message:
> In normalizePath(path.expand(path), winslash, mustWork) :
>   path[1]="\\172.19.2.44\profiles\profiles\me\Documents": Access is denied
>
> Even from cmd.exe in a  C: location
>
> C:\Users\me>R
> Warning message:
> In normalizePath(path.expand(path), winslash, mustWork) :
>
>
>  path[1]="\\172.19.2.44\profiles\profiles\me\Documents": Access
> is denied
> Warning message:
> In normalizePath(path.expand(path), winslash, mustWork) :
>  path[1]="\\172.19.2.44\profiles\profiles\me\Documents": Access is
> denied
> Warning message:
> In normalizePath(path.expand(path), winslash, mustWork) :
>  path[1]="\\172.19.2.44\profiles\profiles\me\Documents": Access is
> denied
> Warning message:
> In normalizePath(path.expand(path), winslash, mustWork) :
>  path[1]="\\172.19.2.44\profiles\profiles\me\Documents": Access is
> denied
>
> Reading
> https://cran.r-project.org/bin/windows/base/rw-FAQ.html#What-are-HOME-and-working-directories_003f,
> first I cannot apply the suggested solution (I cannot see such "shortcut’s
> properties"), and second, I am not interested just in Rgui, or even
> RStudio, but other terminals running R (like VSCode-radian or
> SublimeText-Terminus)
>
> Thanks in advance.
>
> Best wishes,
>
> Iago
>
>
>
> [[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] categorizing data

2022-05-29 Thread Bill Dunlap
You could write a function that deals with one row of your data, based on
the order() function.  E.g.,
  > to_10_30_50
  function(x) {
stopifnot(is.numeric(x), length(x)==3, sum(x)==90, all(x>0))
c(10,30,50)[order(x)]
  }
  
  > to_10_30_50(c(23,41,26))
  [1] 10 50 30
Then loop over the rows.  Since this is a data.frame and not a matrix, you
need to coerce each row from a single-row data.frame to a numeric vector:
  > data <- data.frame(tree=c(32,23,49), shrub=c(11,41,23),
grass=c(47,26,18))
  > for(i in 1:nrow(new)) data[i,] <- to_10_30_50(as.numeric(data[i,]))
  > data
tree shrub grass
  1   301050
  2   105030
  3   503010

-Bill

On Sun, May 29, 2022 at 12:29 PM Janet Choate  wrote:

> Hi R community,
> I have a data frame with three variables, where each row adds up to 90.
> I want to assign a category of low, medium, or high to the values in each
> row - where the lowest value per row will be set to 10, the medium value
> set to 30, and the high value set to 50 - so each row still adds up to 90.
>
> For example:
> Data: Orig
> tree  shrub  grass
> 32 11   47
> 23  41  26
> 49  23  18
>
> Data: New
> tree  shrub  grass
> 30  10  50
> 10   50 30
> 50   30 10
>
> I am not attaching any code here as I have not been able to write anything
> effective! appreciate help with this!
> thank you,
> JC
>
> --
>
> [[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] about opening R script Chinese annotation garble problem

2022-04-25 Thread Bill Dunlap
The answer depends on the encoding of the file containing the Chinese
characters and on the version of R (since you are using Windows).  I copied
your subject line into Wordpad and and added some syntax to make a valid R
expression
  s <- "永创 via R-help"
I then saved it with the type "Unicode Text Document".  In my version of
Wordpad this means UTF-16.  The bytes in the file are
  4.2.0> readBin("Chinese-utf-16.txt", what="raw",
n=file.size("Chinese-utf-16.txt"))
   [1] ff fe 73 00 20 00 3c 00 2d 00 20 00 22 00 38 6c 1b 52
  [19] 20 00 76 00 69 00 61 00 20 00 52 00 2d 00 68 00 65 00
  [37] 6c 00 70 00 22 00 0d 00 0a 00
All the nulls in the file are a hint that this is encoded using UTF-16, not
UTF-8.

With R-4.2.0 (released a few days ago) I can source the file with
  4.2.0> source("Chinese-utf-16.txt", encoding="UTF-16")
  4.2.0> s
  [1] "永创 via R-help"
  4.2.0> Encoding(s)
  [1] "UTF-8"

With R-4.1.2 I get
  > source("Chinese-utf-16.txt", encoding="UTF-16")
  Error in source("Chinese-utf-16.txt", encoding = "UTF-16") :
Chinese-utf-16.txt:1:6: unexpected INCOMPLETE_STRING
  1: s <- "
   ^
  In addition: Warning message:
  In readLines(file, warn = FALSE) :
invalid input found on input connection 'Chinese-utf-16.txt'
  > source(file("Chinese-utf-16.txt", encoding="UTF-16"))
  > s
  [1] " via R-help"
  > source(file("Chinese-utf-16.txt", encoding="UTF-16"), encoding="UTF-8")
  > s
  [1] "永创 via R-help"
  > Encoding(s)
  [1] "UTF-8"
  > charToRaw(s)
   [1] e6 b0 b8 e5 88 9b 20 76 69 61 20 52 2d 68 65 6c 70

R-4.2.0 makes this much easier.

-Bill

On Mon, Apr 25, 2022 at 1:04 AM 永创 via R-help  wrote:

> Garbled characters appear in Chinese annotation when opening program
> script using RGui (see attached picture). I use a variety of methods have
> not been solved, I hope to help me solve this problem. 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] Error with text analysis data

2022-04-13 Thread Bill Dunlap
>  I would always suggest working until the model works, no errors and no
NA values

We agree on that.  However, the error gives you no hint about which
variables are causing the problem.  If it did, then it could only tell
about the first variable with the problem.  I think you would get to your
working model faster if you got NA's for the constant columns and then
could drop them all at once (or otherwise deal with them).

-Bill

On Wed, Apr 13, 2022 at 9:40 AM Ebert,Timothy Aaron  wrote:

> I suspect that it is because you are looking at two types of error, both
> telling you that the model was not appropriate. In the “error in contrasts”
> there is nothing to contrast in the model. For a numerical constant the
> program calculates the standard deviation and ends with a division by zero.
> Division by zero is undefined, or NA.
>
>
>
> I would always suggest working until the model works, no errors and no NA
> values. The reason is that I can get NA in several ways and I need to
> understand why. If I just ignore the NA in my model I may be assuming the
> wrong thing.
>
>
>
> Tim
>
>
>
> *From:* Bill Dunlap 
> *Sent:* Wednesday, April 13, 2022 12:23 PM
> *To:* Ebert,Timothy Aaron 
> *Cc:* Neha gupta ; r-help mailing list <
> r-help@r-project.org>
> *Subject:* Re: [R] Error with text analysis data
>
>
>
> *[External Email]*
>
> Constant columns can be the model when you do some subsetting or are
> exploring a new dataset.  My objection is that constant columns of numbers
> and logicals are fine but those of characters and factors are not.
>
>
>
> -Bill
>
>
>
> On Wed, Apr 13, 2022 at 9:15 AM Ebert,Timothy Aaron 
> wrote:
>
> What is the goal of having a constant in the model? To me that seems
> pointless. Also there is no variability in sexCode regardless of whether
> you call it integer or factor. So the model y ~ sexCode is just a strange
> way to look at the variability in y and it would be better to do something
> like summarize(y) or mean(y) if that was the goal.
>
> Tim
>
> -Original Message-
> From: R-help  On Behalf Of Bill Dunlap
> Sent: Wednesday, April 13, 2022 9:56 AM
> To: Neha gupta 
> Cc: r-help mailing list 
> Subject: Re: [R] Error with text analysis data
>
> [External Email]
>
> This sounds like what I think is a bug in stats::model.matrix.default(): a
> numeric column with all identical entries is fine but a constant character
> or factor column is not.
>
> > d <- data.frame(y=1:5, sex=rep("Female",5)) d$sexFactor <-
> > factor(d$sex, levels=c("Male","Female")) d$sexCode <-
> > as.integer(d$sexFactor) d
>   ysex sexFactor sexCode
> 1 1 FemaleFemale   2
> 2 2 FemaleFemale   2
> 3 3 FemaleFemale   2
> 4 4 FemaleFemale   2
> 5 5 FemaleFemale   2
> > lm(y~sex, data=d)
> Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
>   contrasts can be applied only to factors with 2 or more levels
> > lm(y~sexFactor, data=d)
> Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
>   contrasts can be applied only to factors with 2 or more levels
> > lm(y~sexCode, data=d)
>
> Call:
> lm(formula = y ~ sexCode, data = d)
>
> Coefficients:
> (Intercept)  sexCode
>   3   NA
>
> Calling traceback() after the error would clarify this.
>
> -Bill
>
>
> On Tue, Apr 12, 2022 at 3:12 PM Neha gupta 
> wrote:
>
> > Hello everyone, I have text data with output variable have three
> subgroups.
> > I am using the following code but getting the error message (see error
> > after the code).
> >
> > d=read.csv("SONAR_RULES.csv", stringsAsFactors = FALSE)
> > d$REMEDIATION_FUNCTION=NULL d$DEF_REMEDIATION_GAP_MULT=NULL
> > d$REMEDIATION_BASE_EFFORT=NULL
> >
> > index <- createDataPartition(d$TYPE, p = .70,list = FALSE) tr <-
> > d[index, ] ts <- d[-index, ]
> >
> > ctrl <- trainControl(method = "cv",number=3, index = index, classProbs
> > = TRUE, summaryFunction = multiClassSummary)
> >
> > ran <- train(TYPE ~ ., data = tr,
> > method = "rpart",
> > ## Will create 48 parameter combinations
> > tuneLength = 3,
> > na.action= na.pass,
> > metric = "Accuracy",
> > preProc = c("center", "scale", "nzv"),
> > trControl = ctrl)
> > getTrainPerf(ran)
> >
> > *It gives me error:*
> >
> >

Re: [R] Error with text analysis data

2022-04-13 Thread Bill Dunlap
Constant columns can be the model when you do some subsetting or are
exploring a new dataset.  My objection is that constant columns of numbers
and logicals are fine but those of characters and factors are not.

-Bill

On Wed, Apr 13, 2022 at 9:15 AM Ebert,Timothy Aaron  wrote:

> What is the goal of having a constant in the model? To me that seems
> pointless. Also there is no variability in sexCode regardless of whether
> you call it integer or factor. So the model y ~ sexCode is just a strange
> way to look at the variability in y and it would be better to do something
> like summarize(y) or mean(y) if that was the goal.
>
> Tim
>
> -Original Message-
> From: R-help  On Behalf Of Bill Dunlap
> Sent: Wednesday, April 13, 2022 9:56 AM
> To: Neha gupta 
> Cc: r-help mailing list 
> Subject: Re: [R] Error with text analysis data
>
> [External Email]
>
> This sounds like what I think is a bug in stats::model.matrix.default(): a
> numeric column with all identical entries is fine but a constant character
> or factor column is not.
>
> > d <- data.frame(y=1:5, sex=rep("Female",5)) d$sexFactor <-
> > factor(d$sex, levels=c("Male","Female")) d$sexCode <-
> > as.integer(d$sexFactor) d
>   ysex sexFactor sexCode
> 1 1 FemaleFemale   2
> 2 2 FemaleFemale   2
> 3 3 FemaleFemale   2
> 4 4 FemaleFemale   2
> 5 5 FemaleFemale   2
> > lm(y~sex, data=d)
> Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
>   contrasts can be applied only to factors with 2 or more levels
> > lm(y~sexFactor, data=d)
> Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
>   contrasts can be applied only to factors with 2 or more levels
> > lm(y~sexCode, data=d)
>
> Call:
> lm(formula = y ~ sexCode, data = d)
>
> Coefficients:
> (Intercept)  sexCode
>   3   NA
>
> Calling traceback() after the error would clarify this.
>
> -Bill
>
>
> On Tue, Apr 12, 2022 at 3:12 PM Neha gupta 
> wrote:
>
> > Hello everyone, I have text data with output variable have three
> subgroups.
> > I am using the following code but getting the error message (see error
> > after the code).
> >
> > d=read.csv("SONAR_RULES.csv", stringsAsFactors = FALSE)
> > d$REMEDIATION_FUNCTION=NULL d$DEF_REMEDIATION_GAP_MULT=NULL
> > d$REMEDIATION_BASE_EFFORT=NULL
> >
> > index <- createDataPartition(d$TYPE, p = .70,list = FALSE) tr <-
> > d[index, ] ts <- d[-index, ]
> >
> > ctrl <- trainControl(method = "cv",number=3, index = index, classProbs
> > = TRUE, summaryFunction = multiClassSummary)
> >
> > ran <- train(TYPE ~ ., data = tr,
> > method = "rpart",
> > ## Will create 48 parameter combinations
> > tuneLength = 3,
> > na.action= na.pass,
> > metric = "Accuracy",
> > preProc = c("center", "scale", "nzv"),
> > trControl = ctrl)
> > getTrainPerf(ran)
> >
> > *It gives me error:*
> >
> >
> > *Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
> > contrasts can be applied only to factors with 2 or more levels*
> >
> >
> > *My data is as follow*
> >
> > Rows: 1,819
> > Columns: 14
> > $ PLUGIN_RULE_KEY  "InsufficientBranchCoverage",
> > "InsufficientLin~
> > $ PLUGIN_CONFIG_KEY"", "", "", "", "", "", "", "", "",
> "",
> > "S1120~
> > $ PLUGIN_NAME  "common-java", "common-java",
> > "common-java", "~
> > $ DESCRIPTION  "An issue is created on a file as
> soon
> > as the ~
> > $ SEVERITY "MAJOR", "MAJOR", "MAJOR", "MAJOR",
> > "MAJOR", "~
> > $ NAME "Branches should have sufficient
> > coverage by t~
> > $ DEF_REMEDIATION_FUNCTION "LINEAR", "LINEAR", "LINEAR",
> > "LINEAR_OFFSET",~
> > $ REMEDIATION_GAP_MULT NA, NA, NA, NA, NA, NA, NA, NA, NA,
> NA,
> > NA, NA~
> > $ DEF_REMEDIATION_BASE_EFFORT  "", "", "", "10min", "", "",
> > "5min", "5min", "~
&

Re: [R] Error with text analysis data

2022-04-13 Thread Bill Dunlap
This sounds like what I think is a bug in stats::model.matrix.default(): a
numeric column with all identical entries is fine but a constant character
or factor column is not.

> d <- data.frame(y=1:5, sex=rep("Female",5))
> d$sexFactor <- factor(d$sex, levels=c("Male","Female"))
> d$sexCode <- as.integer(d$sexFactor)
> d
  ysex sexFactor sexCode
1 1 FemaleFemale   2
2 2 FemaleFemale   2
3 3 FemaleFemale   2
4 4 FemaleFemale   2
5 5 FemaleFemale   2
> lm(y~sex, data=d)
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
  contrasts can be applied only to factors with 2 or more levels
> lm(y~sexFactor, data=d)
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
  contrasts can be applied only to factors with 2 or more levels
> lm(y~sexCode, data=d)

Call:
lm(formula = y ~ sexCode, data = d)

Coefficients:
(Intercept)  sexCode
  3   NA

Calling traceback() after the error would clarify this.

-Bill


On Tue, Apr 12, 2022 at 3:12 PM Neha gupta  wrote:

> Hello everyone, I have text data with output variable have three subgroups.
> I am using the following code but getting the error message (see error
> after the code).
>
> d=read.csv("SONAR_RULES.csv", stringsAsFactors = FALSE)
> d$REMEDIATION_FUNCTION=NULL
> d$DEF_REMEDIATION_GAP_MULT=NULL
> d$REMEDIATION_BASE_EFFORT=NULL
>
> index <- createDataPartition(d$TYPE, p = .70,list = FALSE)
> tr <- d[index, ]
> ts <- d[-index, ]
>
> ctrl <- trainControl(method = "cv",number=3, index = index, classProbs =
> TRUE, summaryFunction = multiClassSummary)
>
> ran <- train(TYPE ~ ., data = tr,
> method = "rpart",
> ## Will create 48 parameter combinations
> tuneLength = 3,
> na.action= na.pass,
> metric = "Accuracy",
> preProc = c("center", "scale", "nzv"),
> trControl = ctrl)
> getTrainPerf(ran)
>
> *It gives me error:*
>
>
> *Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
> contrasts can be applied only to factors with 2 or more levels*
>
>
> *My data is as follow*
>
> Rows: 1,819
> Columns: 14
> $ PLUGIN_RULE_KEY  "InsufficientBranchCoverage",
> "InsufficientLin~
> $ PLUGIN_CONFIG_KEY"", "", "", "", "", "", "", "", "", "",
> "S1120~
> $ PLUGIN_NAME  "common-java", "common-java",
> "common-java", "~
> $ DESCRIPTION  "An issue is created on a file as soon
> as the ~
> $ SEVERITY "MAJOR", "MAJOR", "MAJOR", "MAJOR",
> "MAJOR", "~
> $ NAME "Branches should have sufficient
> coverage by t~
> $ DEF_REMEDIATION_FUNCTION "LINEAR", "LINEAR", "LINEAR",
> "LINEAR_OFFSET",~
> $ REMEDIATION_GAP_MULT NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
> NA, NA~
> $ DEF_REMEDIATION_BASE_EFFORT  "", "", "", "10min", "", "", "5min",
> "5min", "~
> $ GAP_DESCRIPTION  "number of uncovered conditions",
> "number of l~
> $ SYSTEM_TAGS  "bad-practice", "bad-practice",
> "convention", ~
> $ IS_TEMPLATE  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0~
> $ DESCRIPTION_FORMAT   "HTML", "HTML", "HTML", "HTML", "HTML",
> "HTML"~
> $ TYPE "CODE_SMELL", "CODE_SMELL",
> "CODE_SMELL", "COD~
>
> [[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] Inserting missing seq number

2022-03-30 Thread Bill Dunlap
stats::approx can do the job:

> approx(x=df$seq, df$count, xout=1:7, method="constant", f=0)
$x
[1] 1 2 3 4 5 6 7

$y
[1] 4 7 7 3 5 5 2

-Bill

On Tue, Mar 29, 2022 at 7:47 PM Jeff Reichman 
wrote:

> R-help
>
> Is there a R function that will insert missing sequence number(s) and then
> fill a missing observation with the preceding value.
>
> For example df <- data.frame(seq = c(1,2,4,5,7), count = c(4,7,3,5,2))
>
>   seq count
> 114
> 227
> 343
> 455
> 572
>
> What I need is
>
>   seq count
> 114
> 227
> 337
> 443
> 555
> 665
> 772
>
> Jeff
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] [External] Funky calculations

2022-02-02 Thread Bill Dunlap
Floats have 23 bits of precision so the rounding is done there instead of
at 52 bits, hence a different example is needed to show the problem with
floats.

bill@Bill-T490:~$ cat b.c
#include 

int main(int argc, char* argv[])
{
float d = 0.4 + 0.4 + 0.4 + 0.4;
printf("0.4+0.4+0.4+0.4 -> %24.17g\n", (double)d);
printf("0.4+0.4+0.4+0.4 == 1.6 -> %s\n", d == 1.0 ? "true" : "false");
    return 0;
}
bill@Bill-T490:~$ gcc b.c
bill@Bill-T490:~$ ./a.out
0.4+0.4+0.4+0.4 ->   1.600238418579
0.4+0.4+0.4+0.4 == 1.6 -> false

There is no getting around the fact that rounding will happen.

-Bill

On Tue, Feb 1, 2022 at 9:06 PM Nathan Boeger  wrote:

>
> I understand this and with C the data type used is important. For this
> type of calculation, I would normally use a float (basic single precision
> is all I require).
>
> #include 
>
> void main() {
>   float foo = (0.4 + 0.2 + 0.30 + 0.1) ;
>   printf("foo: %f , foo > 1: %s \n", foo, (foo > 1.0 ? "true" : "false"));
>   double bar = (0.4 + 0.2 + 0.30 + 0.1) ;
>   printf("bar: %lf , bar > 1: %s \n", bar, (bar > 1.0 ? "true" : "false"));
> }
>
> gcc  c-check.c -o c-check
> ./c-check
> foo: 1.00 , foo > 1: false
> bar: 1.00 , bar > 1: true
>
> Again, it was my mistake for not reading the R-FAQ. I had no idea it would
> spark such a long thread.
>
> Cheers
>
> -nb
>
> On Wed, 2 Feb 2022 at 10:30, Bill Dunlap  wrote:
>
>> The base 2 representation of 0.4 repeats the digit sequence 1001
>> infinitely, hence must be rounded.  The problem occurs in C the same as it
>> does in R.
>>
>> bill@Bill-T490:~$ cat a.c
>> #include 
>>
>> int main(int argc, char* argv[])
>> {
>> double d = 0.4 + 0.3 + 0.2 + 0.1;
>> printf("0.4+0.3+0.2+0.1 -> %24.17g\n", d);
>> printf("0.4+0.3+0.2+0.1 == 1.0 -> %s\n", d == 1.0 ? "true" : "false");
>> return 0;
>> }
>> bill@Bill-T490:~$ gcc a.c
>> bill@Bill-T490:~$ ./a.out
>> 0.4+0.3+0.2+0.1 ->  0.99989
>> 0.4+0.3+0.2+0.1 == 1.0 -> false
>>
>> -Bill
>>
>> On Tue, Feb 1, 2022 at 7:01 PM Nathan Boeger  wrote:
>>
>>> Thank you for this explanation!
>>>
>>> I have a long background in C/C++ and never realized this was such an
>>> issue
>>> with some languages. At least, with trivial single digit decimals. I
>>> understand accuracy issues with very large decimals, repeating or
>>> non-terminating rationals and I have handled them in the past. It makes
>>> me
>>> worried about all the R scripts I have written before (yikes!).
>>>
>>> Cheers
>>>
>>> -nb
>>>
>>> On Wed, 2 Feb 2022 at 02:44, Richard M. Heiberger 
>>> wrote:
>>>
>>> > RShowDoc('FAQ')
>>> >
>>> > then search for 7.31
>>> >
>>> >
>>> > This statement
>>> > "If you stop at a 5 or 7 or 8 and back up to the previous digit, you
>>> round
>>> > up. Else you leave the previous result alone."
>>> > is not quite right.  The recommendation in IEEE 754, and this is how R
>>> > does arithmetic, is to Round Even.
>>> >
>>> > I ilustrate here with decimal, even though R and other programs use
>>> binary.
>>> >
>>> > > x <- c(1.4, 1.5, 1.6, 2.4, 2.5, 2.6, 3.4, 3.5, 3.6, 4.4, 4.5, 4.6)
>>> > > r <- round(x)
>>> > > cbind(x, r)
>>> > x r
>>> >  [1,] 1.4 1
>>> >  [2,] 1.5 2
>>> >  [3,] 1.6 2
>>> >  [4,] 2.4 2
>>> >  [5,] 2.5 2
>>> >  [6,] 2.6 3
>>> >  [7,] 3.4 3
>>> >  [8,] 3.5 4
>>> >  [9,] 3.6 4
>>> > [10,] 4.4 4
>>> > [11,] 4.5 4
>>> > [12,] 4.6 5
>>> > >
>>> >
>>> > Numbers whose last digit is not 5 (when in decimal) round to the
>>> nearest
>>> > integer.
>>> > Numbers who last digit is 5 (1.5, 2.5, 3.5, 4.5 above)
>>> > round to the nearest EVEN integer.
>>> > Hence 1.5 and 3.5 round up to the even numbers 2 and 4.
>>> > 2.5 and 4.5 round down do the even numbers 2 and 4.
>>> >
>>> > This way the round ups and downs average out to 0.  If we always went
>>> up
>>> > from .5 we would have
>>> > an updrift over time.
>>> >
>>> > For even more detail click on the link in FAQ 7.31 to my appendix
>>> > https:// link.springer.com/content/pdf/bbm%3A978-1-4939-2122-5%2F1.pdf
>>> > and search for "Appendix G".
>>> >
>>> > Section G.5 explains Round to Even.
>>> > Sections G.6 onward illustrate specific examples, such as the one that
>>> > started this email thread.
>>> >
>>> > Rich
>>>
>>> [[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] [External] Funky calculations

2022-02-01 Thread Bill Dunlap
The base 2 representation of 0.4 repeats the digit sequence 1001
infinitely, hence must be rounded.  The problem occurs in C the same as it
does in R.

bill@Bill-T490:~$ cat a.c
#include 

int main(int argc, char* argv[])
{
double d = 0.4 + 0.3 + 0.2 + 0.1;
printf("0.4+0.3+0.2+0.1 -> %24.17g\n", d);
printf("0.4+0.3+0.2+0.1 == 1.0 -> %s\n", d == 1.0 ? "true" : "false");
    return 0;
}
bill@Bill-T490:~$ gcc a.c
bill@Bill-T490:~$ ./a.out
0.4+0.3+0.2+0.1 ->  0.99989
0.4+0.3+0.2+0.1 == 1.0 -> false

-Bill

On Tue, Feb 1, 2022 at 7:01 PM Nathan Boeger  wrote:

> Thank you for this explanation!
>
> I have a long background in C/C++ and never realized this was such an issue
> with some languages. At least, with trivial single digit decimals. I
> understand accuracy issues with very large decimals, repeating or
> non-terminating rationals and I have handled them in the past. It makes me
> worried about all the R scripts I have written before (yikes!).
>
> Cheers
>
> -nb
>
> On Wed, 2 Feb 2022 at 02:44, Richard M. Heiberger  wrote:
>
> > RShowDoc('FAQ')
> >
> > then search for 7.31
> >
> >
> > This statement
> > "If you stop at a 5 or 7 or 8 and back up to the previous digit, you
> round
> > up. Else you leave the previous result alone."
> > is not quite right.  The recommendation in IEEE 754, and this is how R
> > does arithmetic, is to Round Even.
> >
> > I ilustrate here with decimal, even though R and other programs use
> binary.
> >
> > > x <- c(1.4, 1.5, 1.6, 2.4, 2.5, 2.6, 3.4, 3.5, 3.6, 4.4, 4.5, 4.6)
> > > r <- round(x)
> > > cbind(x, r)
> > x r
> >  [1,] 1.4 1
> >  [2,] 1.5 2
> >  [3,] 1.6 2
> >  [4,] 2.4 2
> >  [5,] 2.5 2
> >  [6,] 2.6 3
> >  [7,] 3.4 3
> >  [8,] 3.5 4
> >  [9,] 3.6 4
> > [10,] 4.4 4
> > [11,] 4.5 4
> > [12,] 4.6 5
> > >
> >
> > Numbers whose last digit is not 5 (when in decimal) round to the nearest
> > integer.
> > Numbers who last digit is 5 (1.5, 2.5, 3.5, 4.5 above)
> > round to the nearest EVEN integer.
> > Hence 1.5 and 3.5 round up to the even numbers 2 and 4.
> > 2.5 and 4.5 round down do the even numbers 2 and 4.
> >
> > This way the round ups and downs average out to 0.  If we always went up
> > from .5 we would have
> > an updrift over time.
> >
> > For even more detail click on the link in FAQ 7.31 to my appendix
> > https:// link.springer.com/content/pdf/bbm%3A978-1-4939-2122-5%2F1.pdf
> > and search for "Appendix G".
> >
> > Section G.5 explains Round to Even.
> > Sections G.6 onward illustrate specific examples, such as the one that
> > started this email thread.
> >
> > Rich
>
> [[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] NAs are removed

2022-01-14 Thread Bill Dunlap
> fraction <- 0/0
> if (fraction < .5) TRUE else FALSE
Error in if (fraction < 0.5) TRUE else FALSE :
  missing value where TRUE/FALSE needed

-Bill

On Fri, Jan 14, 2022 at 12:55 PM Bert Gunter  wrote:

> Unlikely.
>
> > 1/0
> [1] Inf  ## not NA
>
> Bert
>
> On Fri, Jan 14, 2022 at 12:41 PM Jim Lemon  wrote:
>
> > Hi Neha,
> > You're using the argument "na.omit" in what function? My blind guess
> > is that there's a divide by zero shooting you from behind.
> >
> > Jim
> >
> > On Sat, Jan 15, 2022 at 6:32 AM Neha gupta 
> > wrote:
> > >
> > > Hi everyone
> > >
> > > I use na.omit to remove NAs but still it gives me error
> > >
> > > Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed
> > >
> > > My data is:
> > >
> > > data.frame': 340 obs. of  15 variables:
> > >  $ DepthTree: num  1 1 1 1 1 1 1 1 1 1 ...
> > >  $ NumSubclass  : num  0 0 0 0 0 0 0 0 0 0 ...
> > >  $ McCabe   : num  1 1 1 1 1 1 3 3 3 3 ...
> > >  $ LOC  : num  3 4 3 3 4 4 10 10 10 10 ...
> > >  $ DepthNested  : num  1 1 1 1 1 1 2 2 2 2 ...
> > >  $ CA   : num  1 1 1 1 1 1 1 1 1 1 ...
> > >  $ CE   : num  2 2 2 2 2 2 2 2 2 2 ...
> > >  $ Instability  : num  0.667 0.667 0.667 0.667 0.667 0.667 0.667 0.667
> > > 0.667 0.667 ...
> > >  $ numCovered   : num  0 0 0 0 0 0 0 0 0 0 ...
> > >  $ operator : Factor w/ 16 levels "T0","T1","T2",..: 2 2 4 13 13 13
> > 1 3
> > > 4 7 ...
> > >  $ methodReturn : Factor w/ 22 levels "I","V","Z","method",..: 2 2 2 2
> 2
> > 2
> > > 2 2 2 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.
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/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] Method Guidance

2022-01-13 Thread Bill Dunlap
Suppose your data were represented as parallel vectors "time" and "type",
meaning that at time[i] a type[i] event occurred.  You didn't say what you
wanted if there were a run of "A" or "B".  If you are looking for the time
span between the last of a run of one sort of event and the first of a run
of the other sort of event then the following can be used.

f <- function(time, type, fromType, toType) {
# return times of (fromTime) last of a run of 'fromType' and
# (toTime) first of subsequent run of 'toType for each such transition.
stopifnot(length(time)==length(type),
  !anyNA(type),
  !anyNA(time),
  !is.unsorted(time),
  length(fromType)==1,
  length(toType)==1)
i <- seq_len(length(time)-1)
iBeforeChange <- which((type[i] == fromType) & (type[i+1] == toType))
data.frame(fromTime=time[iBeforeChange], toTime=time[iBeforeChange+1L])
}

E.g.,

> d <- data.frame(time=c(101,102,102,105,107,111,115),
type=c("A","A","B","A","B","B","A"))
> d
  time type
1  101A
2  102A
3  102B
4  105A
5  107B
6  111B
7  115A
> f(time=d$time, type=d$type, fromType="A", toType="B")
  fromTime toTime
1  102102
2  105107
> with(.Last.value, toTime - fromTime)
[1] 0 2
> f(time=d$time, type=d$type, fromType="B", toType="A")
  fromTime toTime
1  102105
2  111115
> with(.Last.value, toTime - fromTime)
[1] 3 4

With the dplyr package you can avoid the index 'i' by using lag() inside of
mutate().  E.g.,

> d |> mutate(AtoB = (lag(type)=="A" & type=="B"))
  time type  AtoB
1  101A FALSE
2  102A FALSE
3  102B  TRUE
4  105A FALSE
5  107B  TRUE
6  111B FALSE
7  115A FALSE

-Bill


On Tue, Jan 11, 2022 at 4:56 PM Jeff Reichman 
wrote:

> R-Help Forum
>
>
>
> Looking for a little guidance. Have an issue were I'm trying to determine
> the time between when Event A happened(In days) to when a subsequent Event
> B
> happens. For Example at Time 1 Evat A happens and subsequently Event B
> happens at the same day (0) and the next day (1) then Event A happens again
> at time 4 and Event B happens the next day and 3 days later so on and so
> forth. I gather there is no function that will do that so I suspect I will
> need to grate so sour of do while loop?  Any suggestions?
>
>
>
>
>
> Time  Event_A   Event_B   Time_B
>
> 1  1  1
> 0
>
> 2  0  1
> 1
>
> 3  0  0
> 0
>
> 4  1  0
> 0
>
> 5  0  1
> 1
>
> 6  0  0
> 0
>
> 7  0  1
> 3
>
> 8  1  1
> 0
>
> 9  0  0
> 0
>
> 10   0  1
> 2
>
>
>
>
> 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] Error: if statement: missing value where TRUE/FALSE needed

2022-01-05 Thread Bill Dunlap
And how does one [easily] download those files from sourceforge?

-Bill

On Wed, Jan 5, 2022 at 10:15 AM Chuck Coleman via R-help <
r-help@r-project.org> wrote:

> This is a rather complex error, for which I created
> https://sourceforge.net/projects/rhelp/files/Metro/ to hold a minimal
> workspace with all files needed to make everything work.  I'm afraid I
> can't make a minimal example because the environment may be involved.  I
> suspect that it is an error with base R itself.  I've verified it in both
> MacOS and Ubuntu Linux using Rstudio 2021.09.1 Build 372 and R 4.1.2.  I'm
> trying to run the command
>
> Metro.imf0 <- extractIMF0(Metro.xts,threshold = 1.7,robust=TRUE)$IMF0
>
> This is the last command in MetroTest.R, which also sets up the
> workspace.  The output is in MetroTest.log.  The error is:
>
> Error in if (xseg[w1] > ub & m == 1) olrmark[wi] = TRUE else if
> (xseg[w1] <  :
>   missing value where TRUE/FALSE needed
> Called from: detectspikes(x, mindex = mindex, threshold = threshold,
> robust = robust)
>
> extractIMF0() calls extractoutliers() which iteratively calls
> detectspikes() using while().  I've put in tracking code to show the
> beginning and end of each iteration of while() and the call to
> detectspikes().
>
> The command producing the error is:
>
>   if (xseg[w1] > ub & m == 1) olrmark[wi] = TRUE
>   else if (xseg[w1] < lb & m == 2) olrmark[wi] = TRUE
>
> This code used to work before R 4.1.2.  (I forget the exact version.)  The
> first time I had this error, I inserted a browser() command right before
> if/else so I could manually check all of the if/else arguments and they
> were nonmissing.  Then, executing the if/else caused a crash, I believe the
> first time it was called.  I then made the browser() statement conditional
> to stop execution if a missing argument were encountered and detectspikes()
> happily passed it and crashed.  Then, I individually called print() for
> each variable.  detectspikes() happily ran several times, then crashed in a
> later call after running for several seconds.  Again, browser() never
> stopped the program.  It is this version that I have verified on both a Mac
> and Ubuntu box.
>
> The first step appears to be to run the code using earlier versions of R.
> (I don't want to tamper with my installations.)  Afterwards, I have no
> idea.  Hence, my post.
>
> Thank you for your help,
> Chuck
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] Using R to convert RDF/XML to

2021-12-31 Thread Bill Dunlap
This is the sort of thing that you should first ask the package maintainer
about; there is an error in the rdf method for write_nquads:

> rdflib:::write_nquads.rdf
function (x, file, ...)
{
rdf_serialize(rdf, file, "nquads", ...)
}

I suspect that the first argument to rdf_serialize should be 'x', not 'rdf'.

Another error in the package is that this function isn't tested.

-Bill


On Fri, Dec 31, 2021 at 6:19 AM Evans, Richard K. (GRC-H000) via R-help <
r-help@r-project.org> wrote:

> Hello R community,
>
> I am a novice R enthusiast trying to use R to convert an RDFdump file [1]
> from Semantic Mediawiki [2] into something that can be natively imported by
> GePhi [3] for graph visualization. The SMW RDFdump file is formatted as
> RDF/XML and I have found the R package "rdflib" [4] and am able to read the
> RDF/XML file into R as an "rdf" object, but it is not clear to me how to
> save the "rdf_serialize" function output to a new file.
>
> What I have so far is:
> library(rdflib)
> NewRDF <- tempfile( "TempFile", fileext = ".nq" )
> MyRDF <- rdf_parse( "MyRDFdumpFile.txt" )
> rdf_serialize( MyRDF, NewRDF, format = "nquads"  )
> write_nquads( MyRDF, NewRDF )
>
> ..but this results in the error: "Error: object of type 'closure' is not
> subsettable"
>
> I will keep struggling with this to learn what I need to learn, but any
> advice to help make quick work of this would be much appreciated.
>
> Thank you in advance.
> /Rich
>
> [1]
> https://www.semantic-mediawiki.org/wiki/Help:Maintenance_script_dumpRDF.php
> [2]
> https://www.semantic-mediawiki.org/wiki/Help:Introduction_to_Semantic_MediaWiki
> [3] https://gephi.org/
> [4] https://cran.r-project.org/web/packages/rdflib/rdflib.pdf
>
> - Richard Evans, NASA GRC - Armstrong Test Facility
>   mailto://richard.k.ev...@nasa.gov
>   http://www.linkedin.com/in/rkevans
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] .Rdata not loading

2021-12-23 Thread Bill Dunlap
And a fourth thing to do:

* dput(tail(n=20, readBin(".RData", what=raw(), n=file.size(".RData"

This can show if the file got truncated.

-Bill

On Thu, Dec 23, 2021 at 5:25 PM Bill Dunlap 
wrote:

> Three things you might try using R (and show the results in this email
> thread):
>
> * load(verbose=TRUE, ".RData") # see how far it gets before stopping
> * file.info(normalizePath(".RData")) # is this the file you think it is?
> * dput(readBin(".RData", what=raw(), n=100))
>
> The last will print some hex numbers that others may be able to
> interpret.  E.g., it may show that this .RData is not from a call to save()
> or save.image().
>
> -Bill
>
> On Thu, Dec 23, 2021 at 11:19 AM Rich Shepard 
> wrote:
>
>> Each time I finish with a session I save the image. Today the saved image
>> did not load and manually running 'load('.RData') fails:
>> > load('.RData')
>> Error in load(".RData") :
>>ReadItem: unknown type 0, perhaps written by later version of R
>> >
>>
>> This has not happened before.
>>
>> Installed is R-4.1.2-x86_64-1_SBo and in the PWD I see:
>> $ ll .RData*
>> -rw-r--r-- 1 rshepard users 28074080 Dec 22 15:32 .RData
>> -rw-r--r-- 1 rshepard users  134 Nov  4 14:57 .RDataTmp
>> -rw-r--r-- 1 rshepard users0 Nov  4 14:57 .RDataTmp1
>>
>> What might be keeping .RData from loading? Is there a maximum size for
>> .RData? The /home partition has 270G available space so that's not
>> limiting.
>>
>> How do I load it?
>>
>> TIA,
>>
>> 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] .Rdata not loading

2021-12-23 Thread Bill Dunlap
Three things you might try using R (and show the results in this email
thread):

* load(verbose=TRUE, ".RData") # see how far it gets before stopping
* file.info(normalizePath(".RData")) # is this the file you think it is?
* dput(readBin(".RData", what=raw(), n=100))

The last will print some hex numbers that others may be able to interpret.
E.g., it may show that this .RData is not from a call to save() or
save.image().

-Bill

On Thu, Dec 23, 2021 at 11:19 AM Rich Shepard 
wrote:

> Each time I finish with a session I save the image. Today the saved image
> did not load and manually running 'load('.RData') fails:
> > load('.RData')
> Error in load(".RData") :
>ReadItem: unknown type 0, perhaps written by later version of R
> >
>
> This has not happened before.
>
> Installed is R-4.1.2-x86_64-1_SBo and in the PWD I see:
> $ ll .RData*
> -rw-r--r-- 1 rshepard users 28074080 Dec 22 15:32 .RData
> -rw-r--r-- 1 rshepard users  134 Nov  4 14:57 .RDataTmp
> -rw-r--r-- 1 rshepard users0 Nov  4 14:57 .RDataTmp1
>
> What might be keeping .RData from loading? Is there a maximum size for
> .RData? The /home partition has 270G available space so that's not
> limiting.
>
> How do I load it?
>
> TIA,
>
> 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] Bug in list.files(full.names=T)

2021-12-20 Thread Bill Dunlap
> grep(value=TRUE, invert=TRUE, "$", strsplit(Sys.getenv("PATH"),
";")[[1]])
 [1] "C:\\rtools40\\usr\\bin"
 [2] "C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath"
 [3] "C:\\Program Files\\ImageMagick-7.0.11-Q16-HDRI"
 [4] "C:\\WINDOWS\\system32"
 [5] "C:\\WINDOWS"
 [6] "C:\\WINDOWS\\System32\\Wbem"
 [7] "C:\\ProgramData\\chocolatey\\bin"
 [8] "C:\\Program Files\\Git\\cmd"
 [9] "C:\\Program Files\\TortoiseSVN\\bin"
[10] "C:\\Program Files\\Docker\\Docker\\resources\\bin"
[11] "C:\\ProgramData\\DockerDesktop\\version-bin"
[12] "C:\\Users\\willi\\AppData\\Local\\Microsoft\\WindowsApps"
[13] "C:\\Users\\willi\\AppData\\Local\\Programs\\Microsoft VS Code\\bin"
[14] "C:\\Users\\willi\\AppData\\Roaming\\npm"
[15] "C:\\Users\\willi\\AppData\\Local\\GitHubDesktop\\bin"
> table(grepl("$", strsplit(Sys.getenv("PATH"), ";")[[1]])) # c. 2:1
against terminal backslash

FALSE  TRUE
   15 8


On Mon, Dec 20, 2021 at 9:30 AM Martin Maechler 
wrote:

> >>>>> Bill Dunlap
> >>>>> on Mon, 20 Dec 2021 08:40:04 -0800 writes:
>
> >>
> >> > Why would one ever *add* a final unneeded path separator,
> >> > unless one wanted it?
> >>
>
> > Good question, but it is common for Windows installer programs to
> add a
> > terminal backslash to PATH entries.  E.g., on my Windows laptop I get
>
> >> grep(value=TRUE, "$", strsplit(Sys.getenv("PATH"), ";")[[1]])
> > [1] "C:\\Python39\\Scripts\\"
> > [2] "C:\\Python39\\"
> > [3] "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\"
> > [4] "C:\\WINDOWS\\System32\\OpenSSH\\"
> > [5] "C:\\Program Files\\nodejs\\"
> > [6] "C:\\Program Files\\Pandoc\\"
> > [7] "C:\\Program Files\\MiKTeX\\miktex\\bin\\x64\\"
> > [8] "C:\\Program Files\\PuTTY\\"
>
> > I did not add those entries by hand; all were added by installer
> programs.
>
> > -Bill
>
> Thanks a lot, Bill,  for giving this part of the picture
> (even though you did not show how many there were in your PATH which
>  did *not* end in `\\` ..)
>
> However the reason for my 2nd post was that I could *not* at all
> confirm what Mario reported, but rather I saw
> having a final "/" and not having it
> to give the *same* behavior on R for Windows versions
> from 3.6.1 to 4.1.2 on our M$ Windows terminal server (2016)
> and now, as I just checked, it also *still* has the same Windows-specific
> behavior in R-devel-ucrt (the one from Tomas Kalibera) :
>
> If I use a trailing `/` or `\\` it is *kept*, but no additional
> fsep (i.e. '/' or `\\`) is added (on Windows) when I use
>
>  list.files(dir, full.names=TRUE)
>
> contrary to what Mario reported (to happen in R 4.1.2, but not R 3.6.1)
>
> 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.


Re: [R] Bug in list.files(full.names=T)

2021-12-20 Thread Bill Dunlap
>
> > Why would one ever *add* a final unneeded path separator,
> > unless one wanted it?
>

Good question, but it is common for Windows installer programs to add a
terminal backslash to PATH entries.  E.g., on my Windows laptop I get

> grep(value=TRUE, "$", strsplit(Sys.getenv("PATH"), ";")[[1]])
[1] "C:\\Python39\\Scripts\\"
[2] "C:\\Python39\\"
[3] "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\"
[4] "C:\\WINDOWS\\System32\\OpenSSH\\"
[5] "C:\\Program Files\\nodejs\\"
[6] "C:\\Program Files\\Pandoc\\"
[7] "C:\\Program Files\\MiKTeX\\miktex\\bin\\x64\\"
[8] "C:\\Program Files\\PuTTY\\"

I did not add those entries by hand; all were added by installer programs.

-Bill

[[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 lm Giving Wrong Results

2021-12-02 Thread Bill Dunlap
On the 'bad' machines, what did you get for
   summary(fit)
   summary(k)
   summary(Z)
   summary(gm*gsd^Z)
?

-Bill

On Thu, Dec 2, 2021 at 6:18 AM Labone, Thomas  wrote:

> In the code below the first and second plots should look pretty much the
> same, the only difference being that the first has n=1000 points and the
> second n=1 points. On two of my Linux machines (info below) the second
> plot is a horizontal line (incorrect answer from lm), but on my Windows 10
> machine and a third Linux machine it works as expected. The interesting
> thing is that the code works as expected for n <= 4095 but fails for
> n>=4096 (which equals 2^12). Can anyone else reproduce this problem? Any
> ideas on how to fix it?
>
> set.seed(132)
>
>
> #~~~
> # This works
> n <- 1000# OK <= 4095
> Z <- qnorm(ppoints(n))
>
> k <- sort(rlnorm(n,log(2131),log(1.61)) / rlnorm(n,log(355),log(1.61)))
>
> quantile(k,probs=c(0.025,0.5,0.975))
> summary(k)
>
> fit <- lm(log(k) ~ Z)
> summary(fit)
>
> gm <- exp(coef(fit)[1])
> gsd <- exp(coef(fit)[2])
> gm
> gsd
>
> plot(Z,k,log="y",xlim=c(-4,4),ylim=c(0.1,100))
> lines(Z,gm*gsd^Z,col="red")
>
>
> #~~~
> #this does not
> n <- 1# fails >= 4096 = 2^12
> Z <- qnorm(ppoints(n))
>
> k <- sort(rlnorm(n,log(2131),log(1.61)) / rlnorm(n,log(355),log(1.61)))
>
> quantile(k,probs=c(0.025,0.5,0.975))
> summary(k)
>
> fit <- lm(log(k) ~ Z)
> summary(fit)
>
> gm <- exp(coef(fit)[1])
> gsd <- exp(coef(fit)[2])
> gm
> gsd
>
> plot(Z,k,log="y",xlim=c(-4,4),ylim=c(0.1,100))
> lines(Z,gm*gsd^Z,col="red")
>
>
>
> #~~~
> > sessionInfo() #for two Linux machines having problem
> R version 4.1.2 (2021-11-01)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Linux Mint 20.2
>
> Matrix products: default
> BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/libmkl_rt.so
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>  LC_MONETARY=en_US.UTF-8
>  [6] LC_MESSAGES=en_US.UTF-8LC_PAPER=en_US.UTF-8   LC_NAME=C
> 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   base
>
> loaded via a namespace (and not attached):
> [1] compiler_4.1.2  Matrix_1.3-4tools_4.1.2 expm_0.999-6
> grid_4.1.2  lattice_0.20-45
>
> #~~
> > sessionInfo() # for a third Linux machine not having the problem
> R version 4.1.1 (2021-08-10)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Linux Mint 19.3
>
> Matrix products: default
> BLAS/LAPACK:
> /opt/intel/compilers_and_libraries_2020.0.166/linux/mkl/lib/intel64_lin/libmkl_rt.so
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  LC_TIME=en_US.UTF-8
>  [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
> LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C  LC_ADDRESS=C
> [10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8
> LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> loaded via a namespace (and not attached):
> [1] compiler_4.1.1 tools_4.1.1
>
>
>
> Thomas R. LaBone
> PhD student
> Department of Epidemiology and Biostatistics
> Arnold School of Public Health
> University of South Carolina
> Columbia, South Carolina USA
>
>
> [[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] Degree symbol as axis label superscript [RESOLVED]

2021-11-30 Thread Bill Dunlap
The following makes degree signs appropriately, as shown in ?plotmath:
plot(68, 20, xlab=expression(degree*F), ylab=expression(degree*C))
If you want the word "degree" spelled out, put it in quotes.

-Bill

On Tue, Nov 30, 2021 at 12:31 PM Rich Shepard 
wrote:

> On Tue, 30 Nov 2021, Rich Shepard wrote:
>
> > Thanks, Andrew. I will.
>
> plotmath didn't have the solution; the use of the LaTeX ^ for a superscript
> had a character or number preceeding it. Using 'degree' prints that string
> on the axis.
>
> What does work is using the unicode for the degree symbol as prefix to
> either C or F. In my case:
> ylab('Water Temperature (\u00B0C)')
> does the job.
>
> I found this solution with the DDG search string, 'degree symbol in R plot
> axis label'. This stackexchange thread has the answer:
> <
> https://stackoverflow.com/questions/51799118/writing-the-symbol-degrees-celsius-in-axis-titles-with-r-plotly
> >
>
> 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] Question about Rfast colMins and colMaxs

2021-11-30 Thread Bill Dunlap
You can use as.matrix() to convert your data.frame to a matrix, but that
loses the speed/space advantages of colMins (as well as causing issues if
some columns are not numeric).  You could write to the maintainer of the
package to ask that data.frames be directly supported.  In the meantime you
could use
   vapply(yourDataFrame, which.min, FUN.VALUE=NA_real_)
or
vapply(yourDataFrame, min, FUN.VALUE=NA_real_)
instead of colMins.

-Bill

On Tue, Nov 30, 2021 at 10:55 AM Stephen H. Dawson, DSL via R-help <
r-help@r-project.org> wrote:

> Hi,
>
>
> I am working to understand the Rfast functions of colMins and colMaxs. I
> worked through the example listed on page 54 of the PDF.
>
> https://cran.r-project.org/web/packages/Rfast/index.html
>
> https://cran.r-project.org/web/packages/Rfast/Rfast.pdf
>
> My data is in a CSV file. So, I bring it into R Studio using:
> Data <- read.csv("./input/DataSet05.csv", header=T)
>
> However, I read the instructions listed on page 54 of the PDF saying I
> need to bring data into R using a matrix. I think read.csv brings the
> data in as a dataframe. I think colMins is failing because it is looking
> for a matrix but finds a dataframe.
>
>  > colMaxs(Data)
> Error in colMaxs(Data) :
>Not compatible with requested type: [type=list; target=double].
>  > colMins(Data, na.rm = TRUE)
> Error in colMins(Data, na.rm = TRUE) :
>unused argument (na.rm = TRUE)
>  > colMins(Data, value = FALSE, parallel = FALSE)
> Error in colMins(Data, value = FALSE, parallel = FALSE) :
>Not compatible with requested type: [type=list; target=double].
>
> QUESTION
> What is the best practice to bring a csv file into R Studio so it can be
> accessed by colMaxs and colMins, please?
>
>
> Thanks,
> --
> *Stephen Dawson, DSL*
> /Executive Strategy Consultant/
> Business & Technology
> +1 (865) 804-3454
> http://www.shdawson.com <http://www.shdawson.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] read_csv() error I cannot find

2021-11-24 Thread Bill Dunlap
Did the 3 warnings come from three separate calls to read_csv?  If so, can
you identify which files caused the warnings?  E.g., change the likes of
   lapply(files, function(file) read_csv(file, ...))
to
   options(warn=1) # report warnings immediately
   lapply(files, function(file){ cat(file, "\n"); read_csv(file, ...)})
Then look at the first lines of those files and see if they have the
expected column names.

-Bill

On Wed, Nov 24, 2021 at 9:46 AM Rich Shepard 
wrote:

> On Wed, 24 Nov 2021, Ivan Krylov wrote:
>
> > This typically happens when you leave a trailing comma at the end of a
> > list() call:
>
> Ivan,
>
> Yes. I figured that out yesterday but didn't change the draft message.
> There
> no longer are any extraneous commas in the script.
>
> Thanks,
>
> 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] R lattice contourplot: select only specific values

2021-11-17 Thread Bill Dunlap
Try using at=c(1.8, 2.8) to specify the contour levels you want (and omit
the cuts= argument).

-Bill

On Wed, Nov 17, 2021 at 5:41 AM Luigi Marongiu 
wrote:

> I have a dataframe of three variables: x, y, z. The value of z are:
> ```
> > unique(df$z)
> [1] 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.6 3.0 2.4 2.8
> ```
> I would like to plot the contour where the data get integer values
> (1.0, 2.0, 3.0) but also highlight where the 1.8 and 2.8 values
> occurred. Thus, I am plotting the data with lattice's contourplot with
> a cut of 3,  and I would like to add a layer with the contours for the
> 2.8 values. A sort of mean and 95% CI margins around it.
> I selected a subset of the original dataframe, but it does not plot
> anything.
> ```
> library(lattice)
> library(latticeExtra)
> ds = subset(df, z == 1.8 | z == 2.8)
> a = contourplot(z ~ y*x, data = df, cuts = 3, lwd = 3, labels=FALSE)
> b = contourplot(Class ~ y*x, data = ds, lwd = 1, col="blue")
> P = a + as.layer(b)
> print(P)
> ```
>
> Is there a way to select only a subset of the contours? If I increase
> `cuts` I get more levels, I am only interested in certain values...
> 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] ggplot2: multiple box plots, different tibbles/dataframes

2021-11-11 Thread Bill Dunlap
I googled for "ggplot2 boxplots by group" and the first hit was
  https://www.r-graph-gallery.com/265-grouped-boxplot-with-ggplot2.html
which displays lots of variants along with the code to produce them.  It
has links to ungrouped boxplots and shows how violin plots can better
display your data.

-Bill

On Thu, Nov 11, 2021 at 5:50 AM Rich Shepard 
wrote:

> On Wed, 10 Nov 2021, Avi Gross via R-help wrote:
>
> > I think many here may not quite have enough info to help you.
>
> Avi,
>
> Actually, you've reflected my thinking.
>
> > But the subject of multiple plots has come up. There are a slew of ways,
> > especially in the ggplot paradigm, to make multiple smaller plots into a
> > larger display showing them in some number of rows and columns, or other
> > ways. Some methods use facet_wrap() or facet_grid() type functionality
> that
> > let you plot multiple subdivisions of the data independently. These
> though
> > generally have to be in some way related.
>
> My experience with facets (which I belive are like latice's conditioned
> trellis plots has each plot in a separate frame in a row, column, or
> matrix.) That won't communicate what I want viewers to see as well as would
> having all in a single frame.
>
> My data represent hydrologic and geochemical conditions at four locations
> along the mainstem of a river. While the period of record for each
> monitoring gauge is different, I want to illustrate how highly variable
> conditions are at each location. The major factor of interest is discharge,
> the volume of water passing a river cross section at the gauge location in
> cubic feet per second. I have created boxplots for each site representing
> the distribution of discharge for the entire data set and I'd like to place
> each of the four horizontal boxplots stacked vertically with the
> southern-most at the bottom and the northern-most at the top (the river
> flows north).
>
> > Yet others let you make many independent graphs and save them and later
> > recombine them in packages like cowplot.
>
> I discovered cowplot yesterday but haven't yet read the PDF or vignette.
>
> > So, although it may also be possible to do whatever it is you want
> within a
> > single plot, it may also make sense to do it as loosely described above.
>
> While I certainly may be wrong, I believe that seeing all four boxplots in
> the same frame makes the differences in distribution most clear.
>
> Thanks,
>
> 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] Fwd: Merging multiple csv files to new file

2021-11-03 Thread Bill Dunlap
The error message arises because you are sometimes delimiting character
strings using non-ASCII open and close double quotes, '“' and '”', instead
of the old-fashioned ones, '"', which have no open or close variants.  This
is a language syntax error, so R didn't try to compute anything.

The others' comments are still valid - you need to read the files named by
these strings to produce R datasets and combine the datasets.

-Bill


On Wed, Nov 3, 2021 at 8:36 AM gabrielle aban steinberg <
gabrielleabansteinb...@gmail.com> wrote:

> Hello, I would like to merge 18 csv files into a master data csv file, but
> each file has a different number of columns (mostly found in one or more of
> the other cvs files) and different number of rows.
>
> I have tried something like the following in R Studio (cloud):
>
> all_data_fit_files <- rbind("dailyActivity_merged.csv",
> "dailyCalories_merged.csv", "dailyIntensities_merged.csv",
> "dailySteps_merged.csv", "heartrate_seconds_merged.csv",
> "hourlyCalories_merged.csv", "hourlyIntensities_merged.csv",
> "hourlySteps_merged.csv", "minuteCaloriesNarrow_merged.csv",
> "minuteCaloriesWide_merged.csv", "minuteIntensitiesNarrow_merged.csv",
> "minuteIntensitiesWide_merged.csv", "minuteMETsNarrow_merged.csv",
> "minuteSleep_merged.csv", "minuteStepsNarrow_merged.csv",
> “minuteStepsWide_merged.csv", "sleepDay_merged.csv",
> "minuteStepsWide_merged.csv", "sleepDay_merged.csv",
> "weightLogInfo_merged.csv")
>
>
>
> But I am getting the following error:
>
> Error: unexpected input in "rlySteps_merged.csv",
> "minuteCaloriesNarrow_merged.csv", "minuteCaloriesWide_merged.csv",
> "minuteIntensitiesNarrow_merged.csv",
> "minuteIntensitiesWide_merged.csv", "minuteMETsNarrow_merged.csv"
>
>
> (Maybe the R Studio free trial/usage is underpowered for my project?)
>
> [[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] Is there a hash data structure for R

2021-11-02 Thread Bill Dunlap
Note that an environment carries a hash table with it, while a named list
does not.  I think that looking up an entry in a list causes a hash table
to be created and thrown away.  Here are some timings involving setting and
getting various numbers of entries in environments and lists.  The times
are roughly linear in n for environments and quadratic for lists.

> vapply(1e3 * 2 ^ (0:6), f, L=new.env(parent=emptyenv()),
FUN.VALUE=NA_real_)
[1] 0.00 0.00 0.00 0.02 0.03 0.06 0.15
> vapply(1e3 * 2 ^ (0:6), f, L=list(), FUN.VALUE=NA_real_)
[1]  0.01  0.03  0.15  0.53  2.66 13.66 56.05
> f
function(n, L, V = sprintf("V%07d", sample(n, replace=TRUE))) {
system.time(for(v in V)L[[v]]<-c(L[[v]],v))["elapsed"]
}

Note that environments do not allow an element named "" (the empty string).

Elements named NA_character_ are treated differently in environments and
lists, neither of which is great.  You may want your hash table functions
to deal with oddball names explicitly.

-Bill

On Tue, Nov 2, 2021 at 8:52 AM Andrew Simmons  wrote:

> If you're thinking about using environments, I would suggest you initialize
> them like
>
>
> x <- new.env(parent = emptyenv())
>
>
> Since environments have parent environments, it means that requesting a
> value from that environment can actually return the value stored in a
> parent environment (this isn't an issue for [[ or $, this is exclusively an
> issue with assign, get, and exists)
> Or, if you've already got your values stored in a list that you want to
> turn into an environment:
>
>
> x <- list2env(listOfValues, parent = emptyenv())
>
>
> Hope this helps!
>
>
> On Tue, Nov 2, 2021, 06:49 Yonghua Peng  wrote:
>
> > But for data.frame the colnames can be duplicated. Am I right?
> >
> > Regards.
> >
> > On Tue, Nov 2, 2021 at 6:29 PM Jan van der Laan 
> wrote:
> >
> > >
> > > True, but in a lot of cases where a python user might use a dict an R
> > > user will probably use a list; or when we are talking about arrays of
> > > dicts in python, the R solution will probably be a data.frame (with
> each
> > > dict field in a separate column).
> > >
> > > Jan
> > >
> > >
> > >
> > >
> > > On 02-11-2021 11:18, Eric Berger wrote:
> > > > One choice is
> > > > new.env(hash=TRUE)
> > > > in the base package
> > > >
> > > >
> > > >
> > > > On Tue, Nov 2, 2021 at 11:48 AM Yonghua Peng  wrote:
> > > >
> > > >> I know this is a newbie question. But how do I implement the hash
> > > structure
> > > >> which is available in other languages (in python it's dict)?
> > > >>
> > > >> I know there is the list, but list's names can be duplicated here.
> > > >>
> > > >>> x <- list(x=1:5,y=month.name,x=3:7)
> > > >>
> > > >>> x
> > > >>
> > > >> $x
> > > >>
> > > >> [1] 1 2 3 4 5
> > > >>
> > > >>
> > > >> $y
> > > >>
> > > >>   [1] "January"   "February"  "March" "April" "May"
> >  "June"
> > > >>
> > > >>   [7] "July"  "August""September" "October"   "November"
> > > "December"
> > > >>
> > > >>
> > > >> $x
> > > >>
> > > >> [1] 3 4 5 6 7
> > > >>
> > > >>
> > > >>
> > > >> Thanks a lot.
> > > >>
> > > >>  [[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
>

Re: [R] tidyverse: read_csv() misses column

2021-11-01 Thread Bill Dunlap
Use the col_type argument to specify your column types.  [Why would you
expect '2009' to be read as a string instead of a number?].  It looks like
an
initial zero causes an otherwise numeric looking entry to be considered
a string (handy for zip codes in the northeastern US).

help(read_csv) says the column type guessing is "not robust" and its
algorithm
doesn't seem to be documented in the help file:

col_types

One of NULL, a cols() specification, or a string. See vignette("readr") for
more details.

If NULL, all column types will be imputed from guess_max rows on the input
interspersed throughout the file. This is convenient (and fast), but not
robust. If the imputation fails, you'll need to increase the guess_max or
supply the correct types yourself.

...

-Bill
On Mon, Nov 1, 2021 at 10:16 AM Rich Shepard 
wrote:
>
> On Mon, 1 Nov 2021, Kevin Thorpe wrote:
>
> > I do not have a specific answer to your particular problem. All I can
say
> > is when a CSV import doesn’t work, it can mean there is something in the
> > CSV file that is unexpected. When read_csv() fails, I will try
read.csv()
> > to compare the results.
>
> Kevin,
>
> Interesting that there's no error:
> cor_disc <- read.csv("../data/cor-disc.csv", header = TRUE)
> ...
> 12496 14171600 2010   3  15 16  45 PDT 1060
> 12497 14171600 2010   3  15 17   0 PDT 1060
> 12498 14171600 2010   3  15 17  15 PDT 1050
> 12499 14171600 2010   3  15 17  45 PDT 1050
>   [ reached 'max' / getOption("max.print") -- omitted 402856 rows ]
> > head(cor_disc)
>site_nbr year mon day hr min  tz disc
> 1 14171600 2009  10  23  0   0 PDT 8750
> 2 14171600 2009  10  23  0  15 PDT 8750
> 3 14171600 2009  10  23  0  30 PDT 8750
> 4 14171600 2009  10  23  0  45 PDT 8750
> 5 14171600 2009  10  23  1   0 PDT 8750
> 6 14171600 2009  10  23  1  15 PDT 8750
> > str(cor_disc)
> 'data.frame':   415355 obs. of  8 variables:
>   $ site_nbr: chr  "14171600" "14171600" "14171600" "14171600" ...
>   $ year: int  2009 2009 2009 2009 2009 2009 2009 2009 2009 2009 ...
>   $ mon : int  10 10 10 10 10 10 10 10 10 10 ...
>   $ day : int  23 23 23 23 23 23 23 23 23 23 ...
>   $ hr  : int  0 0 0 0 1 1 1 1 2 2 ...
>   $ min : int  0 15 30 45 0 15 30 45 0 15 ...
>   $ tz  : chr  "PDT" "PDT" "PDT" "PDT" ...
>   $ disc: int  8750 8750 8750 8750 8750 8750 8750 8730 8730 8730 ...
>
> So, where might I look to see why tidyverse's read_csv() doesn't produce
the
> same results?
>
> 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] I'd like to request that my R CRAN package is not tested on Solaris OS

2021-10-22 Thread Bill Dunlap
gctorture(TRUE) helps too, but it will take a long time.

-Bill

On Fri, Oct 22, 2021 at 11:07 AM lampros mouselimis <
mouselimislamp...@gmail.com> wrote:

> Thank you all for your answers,
>
> I'll give it a try using both valgrind (on linux) and the rhub's linux gcc
> Address Sanitizers (Asan). I've already used rhub to test the package on
> the Solaris OS but it didn't give any error (it seems to me that the
> configurations between CRAN and rhub differ).
>
> Lampros
>
> On Fri, 22 Oct 2021 at 20:31, Henrik Bengtsson 
> wrote:
>
>> I agree with others that this suggests there is a hidden bug in the
>> code.  In addition to running with Valgrind, R-hub's
>>
>> > rhub::check(platform="linux-x86_64-rocker-gcc-san")
>>
>> will compile the native code with the Address Sanitizer (ASan) and the
>> UndefinedBehaviorSanitizer (UBSan).  Those have helped me in the past
>> to track down mistakes, and even spot things I was not aware of.  And
>> it's an ease of mind as a developer when these tools and Valgrind
>> checks give all OK reports.
>>
>> The R-hub services is cross-platform and requires no local setup.
>>
>> /Henrik
>>
>> On Fri, Oct 22, 2021 at 7:41 AM Bill Dunlap 
>> wrote:
>> >
>> > I agree with Stefan.  Try using valgrind (on Linux) to check for memory
>> > misuse:
>> >
>> > R --debugger=valgrind --debugger-args="--leak-check=full
>> > --track-origins=yes"
>> > ...
>> > > yourTests()
>> > > q("no")
>> >
>> > -Bill
>> >
>> >
>> > On Fri, Oct 22, 2021 at 7:30 AM Stefan Evert 
>> > wrote:
>> >
>> > > Just to add my personal cent to this:  I've had similar issues with
>> an R
>> > > package some time ago, which kept crashing somewhat unpredictably in
>> the
>> > > Solaris tests.
>> > >
>> > > Debugging was hard because it only happened on Solaris, but in the
>> end it
>> > > turned out to be due to serious bugs in the code that only happened to
>> > > surface in the Solaris tests.   I would think that it's likely to be
>> the
>> > > same for your package, so the segfaults shouldn't be accepted too
>> readily
>> > > as a platform quirk.
>> > >
>> > > Best
>> > > SE
>> > >
>> > >
>> > > > On 22 Oct 2021, at 15:47, Marc Schwartz via R-help <
>> r-help@r-project.org>
>> > > wrote:
>> > > >
>> > > >
>> > > > 1. The CRAN repository policy here:
>> > > >
>> > > >  https://cran.r-project.org/web/packages/policies.html
>> > > >
>> > > > notes:
>> > > >
>> > > > "Package authors should make all reasonable efforts to provide
>> > > cross-platform portable code. Packages will not normally be accepted
>> that
>> > > do not run on at least two of the major R platforms. Cases for
>> Windows-only
>> > > packages will be considered, but CRAN may not be the most appropriate
>> place
>> > > to host them."
>> > > >
>> > > > That would seem to infer that, with reasonable justification, one
>> may be
>> > > able to make a request of the CRAN maintainers to exclude at least
>> one of
>> > > the OS platforms from testing. A request that would be at the
>> discretion of
>> > > the CRAN maintainers and Solaris, in light of the low market
>> prevalence,
>> > > may be a more common exclusion as you have noted below.
>> > >
>> > > __
>> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > > https://stat.ethz.ch/mailman/listinfo/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.
>>
>

[[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] I'd like to request that my R CRAN package is not tested on Solaris OS

2021-10-22 Thread Bill Dunlap
I agree with Stefan.  Try using valgrind (on Linux) to check for memory
misuse:

R --debugger=valgrind --debugger-args="--leak-check=full
--track-origins=yes"
...
> yourTests()
> q("no")

-Bill


On Fri, Oct 22, 2021 at 7:30 AM Stefan Evert 
wrote:

> Just to add my personal cent to this:  I've had similar issues with an R
> package some time ago, which kept crashing somewhat unpredictably in the
> Solaris tests.
>
> Debugging was hard because it only happened on Solaris, but in the end it
> turned out to be due to serious bugs in the code that only happened to
> surface in the Solaris tests.   I would think that it's likely to be the
> same for your package, so the segfaults shouldn't be accepted too readily
> as a platform quirk.
>
> Best
> SE
>
>
> > On 22 Oct 2021, at 15:47, Marc Schwartz via R-help 
> wrote:
> >
> >
> > 1. The CRAN repository policy here:
> >
> >  https://cran.r-project.org/web/packages/policies.html
> >
> > notes:
> >
> > "Package authors should make all reasonable efforts to provide
> cross-platform portable code. Packages will not normally be accepted that
> do not run on at least two of the major R platforms. Cases for Windows-only
> packages will be considered, but CRAN may not be the most appropriate place
> to host them."
> >
> > That would seem to infer that, with reasonable justification, one may be
> able to make a request of the CRAN maintainers to exclude at least one of
> the OS platforms from testing. A request that would be at the discretion of
> the CRAN maintainers and Solaris, in light of the low market prevalence,
> may be a more common exclusion as you have noted below.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] Package installation help: Stuck at "** byte-compile and prepare package for lazy loading"

2021-09-30 Thread Bill Dunlap
You can define the environment variable R_DONT_USE_TK (to any value) to
avoid this hang caused by code in the tkrplot package.  You do not have to
have an X server running if R_DONT_USE_TK is set.  This will avoid
potential hangs while installing the 23 packages that depend on tkrplot.

tools::package_dependencies("tkrplot", reverse=TRUE, recursive=TRUE)
$tkrplot
 [1] "adoption"   "baggingbwsel"   "biplotbootGUI"
 [4] "cncaGUI""ConvergenceConcepts""fisheyeR"
 [7] "forensim"   "GGEBiplotGUI"   "GUIDE"
[10] "idendr0""InterfaceqPCR"  "multibiplotGUI"
[13] "RclusTool"  "RcmdrPlugin.FuzzyClust"
"RcmdrPlugin.PcaRobust"
[16] "rriskDistributions" "RVideoPoker""SyNet"
[19] "tsgui"  "uHMM"   "GGEBiplots"
[22] "decisionSupport""geneticae"

E.g.,

> install.packages("forensim", type="source",
INSTALL_opts="--no-byte-compile")
Installing package into ‘/home/bill/R-devel/R-build/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/forensim_4.3.tar.gz'
Content type 'application/x-gzip' length 84232 bytes (82 KB)
==
downloaded 82 KB

* installing *source* package ‘forensim’ ...
** package ‘forensim’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -I"/home/bill/R-devel/R-build/include" -DNDEBUG   -I/usr/local/include
  -fpic  -g  -c auxilary.c -o auxilary.o
gcc -I"/home/bill/R-devel/R-build/include" -DNDEBUG   -I/usr/local/include
  -fpic  -g  -c recursFinal.c -o recursFinal.o
gcc -shared -L/usr/local/lib -o forensim.so auxilary.o recursFinal.o
installing to
/home/bill/R-devel/R-build/site-library/00LOCK-forensim/00new/forensim/libs
** R
** data
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation
path
* DONE (forensim)

The downloaded source packages are in
‘/tmp/Rtmp0jqhj9/downloaded_packages’

The relevant code is in tkrplot/src/tcltkimg.c:

EXPORT(int,Rplot_Init)(interp)
Tcl_Interp *interp;
{
/* Added to allow CRAN to disable Tk initialization */
#if !defined(Win32) && !defined(HAVE_AQUA)
if (getenv("R_DONT_USE_TK") != NULL)
return 0;
#endif

-Bill


On Thu, Sep 30, 2021 at 9:35 AM Brodie, Kent  wrote:

> Bill--   BINGO.You have found the answer. After some testing on
> one of my environments where it was always hanging, connecting to the same
> server with an X-Sever running on my workstation did indeed allow the
> package to be installed.
>
>
>
> **GOOD LORD THAT’S RIDICULOUS**   But at least I know.And why it
> doesn’t error out without X running, who knows.
>
>
>
> After a ton more research, I ALSO discovered that there IS a timeout thing
> I can make use of, should I decide to continue just building things and
> ignoring the X-Server requirement for this (and probably some other?)
> packages.
>
>
>
> Before executing R and installing things, set this:
>
>
>
> export _R_INSTALL_PACKAGES_ELAPSED_TIMEOUT_=500
>
>
>
> (value is seconds).   So, the previously-hanging R CMD INSTALL inside of
> the install.packages call will eventually die, and then move on to the next
> package.
>
> This is buried in the documentation but- it’s there and I confirmed it
> works.My example above times out a package install  at 5 minutes.
>
>
>
> While knowing the X requirement is a huge win (thanks again!), I will
> probably stick with just using the timeout thing for what I’m trying to
> accomplish.Installing EVERYTHING from cran will take forever, and more
> than likely my VPN connection to my data center will be disconnected (thank
> you internal IT department) before it finishes.They have some sort of
> internal “you’ve been connected too long” timer that disconnects things
> overnight.   Grr.
>
>
>

[[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] Package installation help: Stuck at "** byte-compile and prepare package for lazy loading"

2021-09-30 Thread Bill Dunlap
I tried this a second time, but with --no-byte-compile, and it hung with a
slightly different traceback

(gdb) where
#0  0x7f95bc4c6689 in __fxstat64 () from
/usr/lib/x86_64-linux-gnu/libc.so.6
#1  0x7f95bc497050 in opendir () from
/usr/lib/x86_64-linux-gnu/libc.so.6
#2  0x7f95b935f1e0 in ?? () from /usr/lib/x86_64-linux-gnu/libtcl8.6.so
#3  0x7f95b9311242 in Tcl_FSMatchInDirectory () from
/usr/lib/x86_64-linux-gnu/libtcl8.6.so
#4  0x7f95b92f3e2b in ?? () from /usr/lib/x86_64-linux-gnu/libtcl8.6.so
#5  0x7f95b92f34c5 in ?? () from /usr/lib/x86_64-linux-gnu/libtcl8.6.so
#6  0x7f95b92f29d8 in ?? () from /usr/lib/x86_64-linux-gnu/libtcl8.6.so
#7  0x7f95b92565f2 in TclNRRunCallbacks () from
/usr/lib/x86_64-linux-gnu/libtcl8.6.so
#8  0x7f95b932bcd9 in Tcl_PkgRequireProc () from
/usr/lib/x86_64-linux-gnu/libtcl8.6.so
#9  0x7f95b932bb06 in Tcl_PkgRequireEx () from
/usr/lib/x86_64-linux-gnu/libtcl8.6.so
#10 0x7f95b96bdbe8 in Rplot_Init (interp=0x5625117460d0) at
tcltkimg.c:465

and when I killed the R subprocess doing the lazyload prep I got a
quasi-infinite stream of error messages:

...
error reading package index file
/home/bill/R-devel/R-build/site-library/tcltk2/tklibs/ttktheme_aquablue/pkgIndex.tcl:
too many nested evaluations (infinite loop?)
error reading package index file
/home/bill/R-devel/R-build/site-library/tcltk2/tklibs/ttktheme_radiance/pkgIndex.tcl:
too many nested evaluations (infinite loop?)
error reading package index file
/home/bill/R-devel/R-build/site-library/tcltk2/tklibs/ttktheme_clearlooks/pkgIndex.tcl:
too many nested evaluations (infinite loop?)
error reading package index file
/home/bill/R-devel/R-build/site-library/tcltk2/tklibs/ttktheme_radiance/pkgIndex.tcl:
can't find package tile
error reading package index file
/home/bill/R-devel/R-build/site-library/tcltk2/tklibs/ttktheme_aquablue/pkgIndex.tcl:
too many nested evaluations (infinite loop?)
error reading package index file
/home/bill/R-devel/R-build/site-library/tcltk2/tklibs/ttktheme_radiance/pkgIndex.tcl:
too many nested evaluations (infinite loop?)
error reading package index file
/home/bill/R-devel/R-build/site-library/tcltk2/tklibs/ttktheme_clearlooks/pkgIndex.tcl:
too many nested evaluations (infinite loop?)
error reading package index file
/home/bill/R-devel/R-build/site-library/tcltk2/tklibs/ttktheme_clearlooks/pkgIndex.tcl:
can't find package tile
error reading package index file
/home/bill/R-devel/R-build/site-library/tcltk2/tklibs/ttktheme_clearlooks/pkgIndex.tcl:
can't find package tile
error reading package index file
/home/bill/R-devel/R-build/site-library/tcltk2/tklibs/ttktheme_clearlooks/pkgIndex.tcl:
can't find package tile
error reading package index file
/home/bill/R-devel/R-build/site-library/tcltk2/tklibs/ttktheme_radiance/pkgIndex.tcl:
can't find package tile
...

-Bill


On Thu, Sep 30, 2021 at 9:00 AM Bill Dunlap 
wrote:

> I just tried installing forensim on R-devel/Ubuntu 20.04/WSL-2.0 without
> an X server (hence DISPLAY was not set).  Loading tktcl gives a warning
> that Tk is not available because DISPLAY is not set.  The installation hung
> after the byte-compile message:
> installing to
> /home/bill/R-devel/R-build/site-library/00LOCK-tkrplot/00new/tkrplot/libs
> ** R
> ** byte-compile and prepare package for lazy loading
> Warning message:
> no DISPLAY variable so Tk is not available
> ** help
> *** installing help indices
> ** building package indices
> ** testing if installed package can be loaded from temporary location
> Warning: no DISPLAY variable so Tk is not available
> Warning: loading Rplot failed
> ** checking absolute paths in shared objects and dynamic libraries
> ** testing if installed package can be loaded from final location
> Warning: no DISPLAY variable so Tk is not available
> Warning: loading Rplot failed
> ** testing if installed package keeps a record of temporary installation
> path
> * DONE (tkrplot)
> * installing *source* package ‘forensim’ ...
> ** package ‘forensim’ successfully unpacked and MD5 sums checked
> ** using staged installation
> ** libs
> gcc -I"/home/bill/R-devel/R-build/include" -DNDEBUG   -I/usr/local/include
>   -fpic  -g  -c auxilary.c -o auxilary.o
> gcc -I"/home/bill/R-devel/R-build/include" -DNDEBUG   -I/usr/local/include
>   -fpic  -g  -c recursFinal.c -o recursFinal.o
> gcc -shared -L/usr/local/lib -o forensim.so auxilary.o recursFinal.o
> installing to
> /home/bill/R-devel/R-build/site-library/00LOCK-forensim/00new/forensim/libs
> ** R
> ** data
> ** inst
> ** byte-compile and prepare package for lazy loading
> [hang]
>
> gdb gives a traceback that I think indicates that the package is trying to
> plot something via tcltk at this point:
>
> Attaching to process 9310
> [New LWP 9315]
> [Thread debugging using libthrea

Re: [R] Package installation help: Stuck at "** byte-compile and prepare package for lazy loading"

2021-09-30 Thread Bill Dunlap
I just tried installing forensim on R-devel/Ubuntu 20.04/WSL-2.0 without an
X server (hence DISPLAY was not set).  Loading tktcl gives a warning that
Tk is not available because DISPLAY is not set.  The installation hung
after the byte-compile message:
installing to
/home/bill/R-devel/R-build/site-library/00LOCK-tkrplot/00new/tkrplot/libs
** R
** byte-compile and prepare package for lazy loading
Warning message:
no DISPLAY variable so Tk is not available
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Warning: no DISPLAY variable so Tk is not available
Warning: loading Rplot failed
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
Warning: no DISPLAY variable so Tk is not available
Warning: loading Rplot failed
** testing if installed package keeps a record of temporary installation
path
* DONE (tkrplot)
* installing *source* package ‘forensim’ ...
** package ‘forensim’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -I"/home/bill/R-devel/R-build/include" -DNDEBUG   -I/usr/local/include
  -fpic  -g  -c auxilary.c -o auxilary.o
gcc -I"/home/bill/R-devel/R-build/include" -DNDEBUG   -I/usr/local/include
  -fpic  -g  -c recursFinal.c -o recursFinal.o
gcc -shared -L/usr/local/lib -o forensim.so auxilary.o recursFinal.o
installing to
/home/bill/R-devel/R-build/site-library/00LOCK-forensim/00new/forensim/libs
** R
** data
** inst
** byte-compile and prepare package for lazy loading
[hang]

gdb gives a traceback that I think indicates that the package is trying to
plot something via tcltk at this point:

Attaching to process 9310
[New LWP 9315]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x7fe20a50f560 in ?? () from /usr/lib/x86_64-linux-gnu/libtcl8.6.so
(gdb) where
#0  0x7fe20a50f560 in ?? () from /usr/lib/x86_64-linux-gnu/libtcl8.6.so
#1  0x7fe20a50f5f2 in TclNRRunCallbacks () from
/usr/lib/x86_64-linux-gnu/libtcl8.6.so
#2  0x7fe20a5e4cd9 in Tcl_PkgRequireProc () from
/usr/lib/x86_64-linux-gnu/libtcl8.6.so
#3  0x7fe20a5e4b06 in Tcl_PkgRequireEx () from
/usr/lib/x86_64-linux-gnu/libtcl8.6.so
#4  0x7fe20a976be8 in Rplot_Init (interp=0x55ae6437a6c0) at
tcltkimg.c:465
#5  0x7fe20a5d1ee3 in ?? () from /usr/lib/x86_64-linux-gnu/libtcl8.6.so
#6  0x7fe20a50f5f2 in TclNRRunCallbacks () from
/usr/lib/x86_64-linux-gnu/libtcl8.6.so
#7  0x7fe20b04d7f0 in dotTclObjv (args=0x55ae6489d210) at
/mnt/c/R/R-svn/trunk/src/library/tcltk/src/tcltk.c:250
#8  0x55ae611cd5a8 in do_External (call=0x55ae6440a270,
op=0x55ae61fe1338, args=0x55ae6489d210, env=0x55ae6489d3d0)
at /mnt/c/R/R-svn/trunk/src/main/dotcode.c:576
#9  0x55ae6122a0b3 in bcEval (body=0x55ae6440a190, rho=0x55ae6489d3d0,
useCache=TRUE)
at /mnt/c/R/R-svn/trunk/src/main/eval.c:7128
#10 0x55ae6121644a in Rf_eval (e=0x55ae6440a190, rho=0x55ae6489d3d0) at
/mnt/c/R/R-svn/trunk/src/main/eval.c:740
#11 0x55ae61215fda in forcePromise (e=0x55ae6489d398) at
/mnt/c/R/R-svn/trunk/src/main/eval.c:568
#12 0x55ae61220b80 in FORCE_PROMISE (value=0x55ae6489d398,
symbol=0x55ae62282a08, rho=0x55ae6489d248,
keepmiss=FALSE) at /mnt/c/R/R-svn/trunk/src/main/eval.c:5149
#13 0x55ae61220d2f in getvar (symbol=0x55ae62282a08,
rho=0x55ae6489d248, dd=FALSE, keepmiss=FALSE,
vcache=0x7fe20b2ec1f0, sidx=1) at
/mnt/c/R/R-svn/trunk/src/main/eval.c:5190

Henrik, can you reproduce this if you undefine DISPLAY?

-Bill




On Wed, Sep 29, 2021 at 7:48 PM Henrik Bengtsson 
wrote:

> I just tried on an up-to-date CentOS 7 with R 4.1.1 built from source
> using gcc 8.3.1 (from SCL devtoolset-8; so not the default gcc 4.8.5),
> and it works there.  If of any help, here's the output when installing
> to user's personal package library:
>
> > chooseCRANmirror(ind = 1)
> > install.packages("forensim")
> Installing package into
> ‘/c4/home/henrik/R/x86_64-pc-linux-gnu-library/4.1-CBI-gcc8’
> (as ‘lib’ is unspecified)
> trying URL 'https://cloud.r-project.org/src/contrib/forensim_4.3.tar.gz'
> Content type 'application/x-gzip' length 84232 bytes (82 KB)
> ==
> downloaded 82 KB
>
> * installing *source* package ‘forensim’ ...
> ** package ‘forensim’ successfully unpacked and MD5 sums checked
> ** using staged installation
> ** libs
> gcc -I"/software/c4/cbi/software/R-4.1.1-gcc8/lib64/R/include"
> -DNDEBUG   -I/usr/local/include   -fpic  -g -O2  -c auxilary.c -o
> auxilary.o
> gcc -I"/software/c4/cbi/software/R-4.1.1-gcc8/lib64/R/include"
> -DNDEBUG   -I/usr/local/include   -fpic  -g -O2  -c recursFinal.c -o
> recursFinal.o
> gcc -shared -L/software

Re: [R] Rdversion ???

2021-09-28 Thread Bill Dunlap
tools:::prepare2_Rd contains the lines
## FIXME: we no longer make any use of \Rdversion
version <- which(sections == "\\Rdversion")
if (length(version) > 1L)
stopRd(Rd[[version[2L]]], Rdfile,
   "Only one \\Rdversion declaration is allowed")
so I am guessing you can ignore any \Rdversion declarations.

-Bill


On Tue, Sep 28, 2021 at 2:57 PM Rolf Turner  wrote:

>
> I just noticed that a help file in one of my packages contains,
> as the second line (just after the \name{ }  macro), the line
>
> > \Rdversion{1.1}
>
> I have no idea how it got there.  I can find no reference to this
> macro in WRE, but by doing some groping, err, grepping around I have
> discovered its presence in a number of help files for other packages.
>
> Can anyone explain to me what it's for, and what its provenance is?
>
> Is it important?
>
> Thanks for any enlightenment.
>
> 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] Reading File Sizes: very slow!

2021-09-25 Thread Bill Dunlap
On my Windows 10 laptop I see evidence of the operating system caching
information about recently accessed files.  This makes it hard to say how
the speed might be improved.  Is there a way to clear this cache?

> system.time(L1 <- size.f.pkg(R.home("library")))
   user  system elapsed
   0.482.81   30.42
> system.time(L2 <- size.f.pkg(R.home("library")))
   user  system elapsed
   0.351.101.43
> identical(L1,L2)
[1] TRUE
> length(L1)
[1] 30
> length(dir(R.home("library"),recursive=TRUE))
[1] 12949

On Sat, Sep 25, 2021 at 8:12 AM Leonard Mada via R-help <
r-help@r-project.org> wrote:

> Dear List Members,
>
>
> I tried to compute the file sizes of each installed package and the
> process is terribly slow.
>
> It took ~ 10 minutes for 512 packages / 1.6 GB total size of files.
>
>
> 1.) Package Sizes
>
>
> system.time({
>  x = size.pkg(file=NULL);
> })
> # elapsed time: 509 s !!!
> # 512 Packages; 1.64 GB;
> # R 4.1.1 on MS Windows 10
>
>
> The code for the size.pkg() function is below and the latest version is
> on Github:
>
> https://github.com/discoleo/R/blob/master/Stat/Tools.CRAN.R
>
>
> Questions:
> Is there a way to get the file size faster?
> It takes long on Windows as well, but of the order of 10-20 s, not 10
> minutes.
> Do I miss something?
>
>
> 1.b.) Alternative
>
> It came to my mind to read first all file sizes and then use tapply or
> aggregate - but I do not see why it should be faster.
>
> Would it be meaningful to benchmark each individual package?
>
> Although I am not very inclined to wait 10 minutes for each new try out.
>
>
> 2.) Big Packages
>
> Just as a note: there are a few very large packages (in my list of 512
> packages):
>
> 1  123,566,287   BH
> 2  113,578,391   sf
> 3  112,252,652rgdal
> 4   81,144,868   magick
> 5   77,791,374 openNLPmodels.en
>
> I suspect that sf & rgdal have a lot of duplicated data structures
> and/or duplicate code and/or duplicated libraries - although I am not an
> expert in the field and did not check the sources.
>
>
> Sincerely,
>
>
> Leonard
>
> ===
>
>
> # Package Size:
> size.f.pkg = function(path=NULL) {
>  if(is.null(path)) path = R.home("library");
>  xd = list.dirs(path = path, full.names = FALSE, recursive = FALSE);
>  size.f = function(p) {
>  p = paste0(path, "/", p);
>  sum(file.info(list.files(path=p, pattern=".",
>  full.names = TRUE, all.files = TRUE, recursive = TRUE))$size);
>  }
>  sapply(xd, size.f);
> }
>
> size.pkg = function(path=NULL, sort=TRUE, file="Packages.Size.csv") {
>  x = size.f.pkg(path=path);
>  x = as.data.frame(x);
>  names(x) = "Size"
>  x$Name = rownames(x);
>  # Order
>  if(sort) {
>  id = order(x$Size, decreasing=TRUE)
>  x = x[id,];
>  }
>  if( ! is.null(file)) {
>  if( ! is.character(file)) {
>  print("Error: Size NOT written to file!");
>  } else write.csv(x, file=file, row.names=FALSE);
>  }
>  return(x);
> }
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] Trying to Learn Details of Grid Graphics, Help Page Errors

2021-09-23 Thread bill
Hi Paul,

Thanks very much for the pointer!

With that and a bit more investigation, I was able to make the following
functions that seem to work in initial testing.

Thanks,

Bill

library(grid)

# The no_clipping function indicates if a shape is clipped in any dimension
# relative to the entire device.  It should work for any rectangular shaped
# grob.
no_clipping <- function(x) {
  # Check the cardinal directions and corners to allow for any rotation
  angles <- seq(0, 3.5, by=0.5)*90
  if ("rot" %in% names(x)) {
# At least text grobs have a "rot" attribute
angles <- angles + (x$rot*pi/180)
  }
  edges_raw <-
grid::deviceLoc(
  x=grid::grobX(x, theta=angles),
  y=grid::grobY(x, theta=angles)
)
  edges <-
list(
  x=grid::convertX(edges_raw$x, unitTo="cm", valueOnly=TRUE),
  y=grid::convertY(edges_raw$y, unitTo="cm", valueOnly=TRUE)
)
  d_size <- dev.size(units="cm")
  c(
bottom=0 <= min(edges$y),
top=max(edges$y) <= d_size[2],
left=0 <= min(edges$x),
right=max(edges$x) <= d_size[1]
  )
}

makeContent.text <- function(x) {
  if (!all(no_clipping(x))) {
warning(
  "Graphics text is outside of the device: ",
  paste0("'", x$label, "'", collapse=", ")
)
  }
  x
}

Code I used for testing:

graphics.off()
foo <- grid.text(label="foo bar", x=0.95, y=0.9)
no_clipping(foo)
graphics.off()
foo <- grid.text(label="foo bar", x=0.9, y=0.9)
no_clipping(foo)
graphics.off()
foo <- grid.text(label="foo bar", x=0.95, y=0.9, rot=45)
no_clipping(foo)
foo <- grid.text(label="foo bar", x=0.96, y=0.9, rot=45)
no_clipping(foo)
graphics.off()
foo <- grid.text(label="foo bar", x=0.96, y=0.9, rot=80)
no_clipping(foo)
graphics.off()
foo <- grid.rect(x=0.8, y=0.8, width=0.15, height=0.15, default.units="npc",
just=c(0, 0))
no_clipping(foo)
graphics.off()
vp <- viewport(angle=45)
foo <- grid.rect(x=0.8, y=0.8, width=0.15, height=0.15, default.units="npc",
just=c(0, 0), vp=vp)
no_clipping(foo)

# It also works with ggplot2
library(ggplot2)
data_with_long_names <-
  data.frame(
A=c(paste0(rep(LETTERS, 3), collapse=""), "ab", paste0(rep(letters, 3),
collapse="")),
B=1
  )

# Feature request: This gives a warning
ggplot(data_with_long_names, aes(x=A, y=B)) +
  geom_point()

ggplot(data_with_long_names, aes(x=A, y=B)) +
  geom_point() +
  theme(
axis.text.x=element_text(angle=45, hjust=1, vjust=1, size=rel(0.5))
  )

-Original Message-
From: Paul Murrell  
Sent: Wednesday, September 22, 2021 4:50 PM
To: b...@denney.ws; r-help@r-project.org
Subject: Re: [R] Trying to Learn Details of Grid Graphics, Help Page Errors

Hi

The first place you should probably start (given where you are right
now) is this R Journal article ...

https://journal.r-project.org/archive/2013/RJ-2013-035/RJ-2013-035.pdf

In brief, the drawDetails() function has been (almost entirely) superceded
by the makeContent() function.

The best overall reference is probably the "R Graphics" book (3rd edition,
chapts 6, 7, & 8).  Unfortunately, because the first edition came out in
2005, that is an Olde Worlde pay-for-a-print-version book (and probably will
be until something stupid like 50 years after I have gone).  Or maybe you
are lucky and work for a first-world university that has purchased access to
an electronic version.

Thanks for pointing out the problems with the drawDetails() help page; I
will need to fix that.

Paul

On 9/23/2021 2:21 AM, b...@denney.ws wrote:
> Hello,
> 
> 
> 
> I'm trying to learn the details of grid graphics. Specifically, I'm 
> trying to create a check that will give a warning or error if text 
> goes outside of the visible plot area. (See
> https://github.com/tidyverse/ggplot2/issues/3282
> <https://github.com/tidyverse/ggplot2/issues/3282>
> for an example of what I
> mean.)
> 
> 
> 
> In my digging, I think that the right way to do this will be to add 
> either a drawDetails, preDrawDetails, or postDrawDetails method for the
"text" class.
> My questions are: Is that the right way to do it or should I be 
> looking elsewhere? Or, is there already a way to do this?
> 
> 
> 
> As I was digging in and trying to learn how to do it, I tried to 
> follow some of the examples from the help page for drawDetails 
> (?drawDetails). But, the suggested functions to review do not exist. 
> Specifically, I wanted to look at grid:::preDrawDetails.frame 
> mentioned in the second paragraph of the Details section of the help page,
and it doesn't exist.
> grid:::drawDetails.xaxis and grid:::postDrawDetails.frame also do not 
> exist (mentioned in the next two paragraphs).
> 
> 

[R] Trying to Learn Details of Grid Graphics, Help Page Errors

2021-09-22 Thread bill
Hello,

 

I'm trying to learn the details of grid graphics.  Specifically, I'm trying
to create a check that will give a warning or error if text goes outside of
the visible plot area.  (See
https://github.com/tidyverse/ggplot2/issues/3282 for an example of what I
mean.)

 

In my digging, I think that the right way to do this will be to add either a
drawDetails, preDrawDetails, or postDrawDetails method for the "text" class.
My questions are:  Is that the right way to do it or should I be looking
elsewhere?  Or, is there already a way to do this?

 

As I was digging in and trying to learn how to do it, I tried to follow some
of the examples from the help page for drawDetails (?drawDetails).  But, the
suggested functions to review do not exist.  Specifically, I wanted to look
at grid:::preDrawDetails.frame mentioned in the second paragraph of the
Details section of the help page, and it doesn't exist.
grid:::drawDetails.xaxis and grid:::postDrawDetails.frame also do not exist
(mentioned in the next two paragraphs).

 

I would try to make patch, but there is no preDrawDetails or postDrawDetails
method in grid that has any content.  For drawDetails, there are many
choices, and since I'm learning, I'm not sure which would be the best to use
as an example.

 

Thanks,

 

Bill


[[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] 'Double to logical' error

2021-09-07 Thread Bill Dunlap
Thanks.  If you can still reproduce the problem, what did
rlang::last_trace()
report?

-Bill

On Tue, Sep 7, 2021 at 3:37 AM John Tully 
wrote:

> Thank you
>
> I ran:
>
> ```{r}
> rlang::last_error()
> ```
>
> Here is the output:
>
> 
> Assigned data `single_study_df` must be compatible with existing data.
> ℹ Error occurred for column `third_ventricle_mn`.
> x Can't convert from  to  due to loss of precision.
> * Locations: 1, 2.
> Backtrace:
> Run `rlang::last_trace()` to see the full context.
>
>
>
>
> --
> *From:* Bill Dunlap 
> *Sent:* Monday, September 6, 2021 5:36 PM
> *To:* John Tully 
> *Cc:* r-help@R-project.org ; McCutcheon, Robert <
> robert.mccutch...@kcl.ac.uk>
> *Subject:* Re: [R] 'Double to logical' error
>
> >  Run `rlang::last_error()` to see where the error occurred
>
> What did rlang::last_error() show?
>
> -Bill
>
>
> On Mon, Sep 6, 2021 at 9:19 AM John Tully 
> wrote:
>
> Dear colleagues
> >
> > in conducting a meta-analysis (of MRI data) I am running into the
> repeated issue:
> >
> > Error: Assigned data `single_study_df` must be compatible with existing
> data. ℹ Error occurred for column `accumbens_sd`. x Can't convert from
>  to  due to loss of precision. * Locations: 1, 2. Run
> `rlang::last_error()` to see where the error occurred.
> >
> > This follows the commands
> >
> > for (region in regions){
> >for (study in unique(df$studyid)){
> >  single_study_df <- df %>% filter(studyid==study)
> >  if (is.na(single_study_df[sprintf('%s_mn', region)][[1]]) & 
> > !is.na(single_study_df[sprintf('%s_mn_l',
> region)])){
> >df <- calc_bilat(study, region, r, df)
> >  }
> >}
> > }
> >
> >
> > My colleague (cc'd) believed it may be an issue with tidyverse version,
> however using an older version (1.2.1), the issue persists. note
> 'accumbens' is the first of many columns so I suspect this is why it flags
> this up.
> >
> > I would greatly value your input on this matter
> >
> > Kind regards
> >
> > John Tully
> >
> >
> >
> >
>
>
>
>
> This message and any attachment are intended solely for the addressee
> and may contain confidential information. If you have received this
> message in error, please contact the sender and delete the email and
> attachment.
>
> Any views or opinions expressed by the author of this email do not
> necessarily reflect the views of the University of Nottingham. Email
> communications with the University of Nottingham may be monitored
> where permitted by law.
>
>
>
>
>
> [[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 message and any attachment are intended solely for the addressee
> and may contain confidential information. If you have received this
> message in error, please contact the sender and delete the email and
> attachment.
>
> Any views or opinions expressed by the author of this email do not
> necessarily reflect the views of the University of Nottingham. Email
> communications with the University of Nottingham may be monitored
> where permitted by law.
>
>
>
>
>

[[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] 'Double to logical' error

2021-09-06 Thread Bill Dunlap
>  Run `rlang::last_error()` to see where the error occurred

What did rlang::last_error() show?

-Bill


On Mon, Sep 6, 2021 at 9:19 AM John Tully 
wrote:

> Dear colleagues
> >
> > in conducting a meta-analysis (of MRI data) I am running into the
> repeated issue:
> >
> > Error: Assigned data `single_study_df` must be compatible with existing
> data. ℹ Error occurred for column `accumbens_sd`. x Can't convert from
>  to  due to loss of precision. * Locations: 1, 2. Run
> `rlang::last_error()` to see where the error occurred.
> >
> > This follows the commands
> >
> > for (region in regions){
> >for (study in unique(df$studyid)){
> >  single_study_df <- df %>% filter(studyid==study)
> >  if (is.na(single_study_df[sprintf('%s_mn', region)][[1]]) & 
> > !is.na(single_study_df[sprintf('%s_mn_l',
> region)])){
> >df <- calc_bilat(study, region, r, df)
> >  }
> >}
> > }
> >
> >
> > My colleague (cc'd) believed it may be an issue with tidyverse version,
> however using an older version (1.2.1), the issue persists. note
> 'accumbens' is the first of many columns so I suspect this is why it flags
> this up.
> >
> > I would greatly value your input on this matter
> >
> > Kind regards
> >
> > John Tully
> >
> >
> >
> >
>
>
>
>
> This message and any attachment are intended solely for the addressee
> and may contain confidential information. If you have received this
> message in error, please contact the sender and delete the email and
> attachment.
>
> Any views or opinions expressed by the author of this email do not
> necessarily reflect the views of the University of Nottingham. Email
> communications with the University of Nottingham may be monitored
> where permitted by law.
>
>
>
>
>
> [[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] Calculate daily means from 5-minute interval data

2021-09-05 Thread Bill Dunlap
What is the best way to read (from a text file) timestamps from the fall
time change, where there are two 1:15am's?  E.g., here is an extract from a
US Geological Survey web site giving data on the river through our county
on 2020-11-01, when we changed from PDT to PST,
https://nwis.waterdata.usgs.gov/wa/nwis/uv/?cb_00010=on&cb_00060=on&cb_00065=on&format=rdb&site_no=12200500&period=&begin_date=2020-11-01&end_date=2020-11-05
.

The timestamps include the date and time as well as PDT or PST.

river <-
c("datetime,tz,discharge,height,temp",
  "2020-11-01 00:00,PDT,20500,16.44,9.3",
  "2020-11-01 00:15,PDT,20500,16.44,9.3",
  "2020-11-01 00:30,PDT,20500,16.43,9.3",
  "2020-11-01 00:45,PDT,20400,16.40,9.3",
  "2020-11-01 01:00,PDT,20400,16.40,9.3",
  "2020-11-01 01:00,PST,20200,16.34,9.2",
  "2020-11-01 01:15,PDT,20400,16.39,9.3",
  "2020-11-01 01:15,PST,20200,16.34,9.2",
  "2020-11-01 01:30,PDT,20300,16.37,9.2",
  "2020-11-01 01:30,PST,20100,16.31,9.2",
  "2020-11-01 01:45,PDT,20300,16.35,9.2",
  "2020-11-01 01:45,PST,20100,16.29,9.2",
  "2020-11-01 02:00,PST,20100,16.29,9.2",
  "2020-11-01 02:15,PST,2,16.27,9.1",
  "2020-11-01 02:30,PST,2,16.26,9.1"
  )
d <- read.table(text=river, sep=",",header=TRUE)

The entries are obviously not in time order.

Is there a simple way to read the timedate and tz columns together?  One
way is to use d$tz to construct an offset that can be read with
strptime's "%z".

> d$POSIXct <-
as.POSIXct(paste(d$datetime,ifelse(d$tz=="PDT","-0700","-0800")),
format="%Y-%m-%d %H:%M %z")
> d
   datetime  tz discharge height temp POSIXct
1  2020-11-01 00:00 PDT 20500  16.44  9.3 2020-11-01 00:00:00
2  2020-11-01 00:15 PDT 20500  16.44  9.3 2020-11-01 00:15:00
3  2020-11-01 00:30 PDT 20500  16.43  9.3 2020-11-01 00:30:00
4  2020-11-01 00:45 PDT 20400  16.40  9.3 2020-11-01 00:45:00
5  2020-11-01 01:00 PDT 20400  16.40  9.3 2020-11-01 01:00:00
6  2020-11-01 01:00 PST 20200  16.34  9.2 2020-11-01 01:00:00
7  2020-11-01 01:15 PDT 20400  16.39  9.3 2020-11-01 01:15:00
8  2020-11-01 01:15 PST 20200  16.34  9.2 2020-11-01 01:15:00
9  2020-11-01 01:30 PDT 20300  16.37  9.2 2020-11-01 01:30:00
10 2020-11-01 01:30 PST 20100  16.31  9.2 2020-11-01 01:30:00
11 2020-11-01 01:45 PDT 20300  16.35  9.2 2020-11-01 01:45:00
12 2020-11-01 01:45 PST 20100  16.29  9.2 2020-11-01 01:45:00
13 2020-11-01 02:00 PST 20100  16.29  9.2 2020-11-01 02:00:00
14 2020-11-01 02:15 PST 2  16.27  9.1 2020-11-01 02:15:00
15 2020-11-01 02:30 PST 2  16.26  9.1 2020-11-01 02:30:00
> with(d[order(d$POSIXct),], plot(temp)) # monotonic temperature

-Bill


On Thu, Sep 2, 2021 at 12:41 PM Jeff Newmiller 
wrote:

> Regardless of whether you use the lower-level split function, or the
> higher-level aggregate function, or the tidyverse group_by function, the
> key is learning how to create the column that is the same for all records
> corresponding to the time interval of interest.
>
> If you convert the sampdate to POSIXct, the tz IS important, because most
> of us use local timezones that respect daylight savings time, and a naive
> conversion of standard time will run into trouble if R is assuming daylight
> savings time applies. The lubridate package gets around this by always
> assuming UTC and giving you a function to "fix" the timezone after the
> conversion. I prefer to always be specific about timezones, at least by
> using so something like
>
> Sys.setenv( TZ = "Etc/GMT+8" )
>
> which does not respect daylight savings.
>
> Regarding using character data for identifying the month, in order to have
> clean plots of the data I prefer to use the trunc function but it returns a
> POSIXlt so I convert it to POSIXct:
>
> discharge$sampmonthbegin <- as.POSIXct( trunc( discharge$sampdate,
> units = "months" ) )
>
> Then any of various ways can be used to aggregate the records by that
> column.
>
> On September 2, 2021 12:10:15 PM PDT, Andrew Simmons 
> wrote:
> >You could use 'split' to create a list of data frames, and then apply a
> >function to each to get the means and sds.
> >
> >
> >cols <- "cfs"  # add more as necessary
> >S <- split(discharge[cols], format(discharge$sampdate, format = "%Y-%m"))
> >means <- do.call("rbind", lapply(S, colMeans, na.rm = TRUE))
> >sds   <- do.call("rbind", lapply(S, function(xx) sapply(xx, sd, na.rm =
> >TRUE)))
> >
> >On Thu, Sep 2, 2021 at 3:01 PM Rich Shepard 
> >wrote:

Re: [R] What if there's nothing to dispatch on?

2021-09-01 Thread Bill Dunlap
Is this the kind of thing you are looking for?  It separates the scoping
issue from the method dispatch by defining another S3-generic function,
".foo".

> foo <- function(x, ..., data=NULL) with(data, .foo(x, ...))
> .foo <- function(x, ...) UseMethod(".foo")
> .foo.default <- function(x, ...) cat("default method\n")
> .foo.integer <- function(x, ...) cat("integer method\n")
> .foo.formula <- function(x, ...) cat("formula method\n")
>
> rm(x)
Warning message:
In rm(x) : object 'x' not found
> foo(32L)
integer method
> foo(y~x)
formula method
> foo(x, data=list(x=2.7))
default method
> x <- 45L ; foo(x)
integer method
> x <- 45L ; foo(x, data=list(x=3.4))
default method
> x <- 45L ; foo(x, data=list(x=Y~X1+X2))
formula method

On Wed, Sep 1, 2021 at 3:30 PM Rolf Turner  wrote:

>
> On Wed, 1 Sep 2021 05:35:03 -0400
> Duncan Murdoch  wrote:
>
> > On 31/08/2021 11:59 p.m., Rolf Turner wrote:
> > >
> > > I'm trying to build a pair of (S3) methods, a "formula" method and a
> > > "default" method.  The methods have a "data" argument.  If the
> > > variables in question cannot be found in "data" then they should be
> > > sought in the global environment.
> > >
> > > My problem is that the generic dispatches on its first argument,
> > > which may be a formula (in which case it of course dispatches to
> > > the formula method) or the first of the variables.  If this
> > > variable exists in the global environment then all is well.  But if
> > > it doesn't exist there, then the generic falls over with an error
> > > of the form "object 'x' not found" --- because there isn't anything
> > > to dispatch on.
> > >
> > > I'd *like* to be able to tell the generic that if "x" is not found
> > > then it should dispatch to the default method (which will, if the
> > > call is sensible, find "x" in "data").
> > >
> > > Is there any way to tell the generic to do this?
> > >
> > > Or is there any other way out of this dilemma? (Other than "Give up
> > > and go to the pub", which I cannot currently do since Auckland is
> > > in Level 4 lockdown. :-) )
> > >
> >
> > That design is probably not a good idea:  what if one of the
> > variables in data matches the name of some other object in the global
> > environment? Then it would dispatch on that other object, and things
> > won't go well.
> >
> > But here's a way to shoot yourself in the foot:
> >
> > function(x) {
> >x1 <- try(x, silent = TRUE)
> >if (inherits(x1, "try-error"))
> >  foo.default(x)
> >else
> >  UseMethod("foo", x)
> > }
> >
> > Happy shooting!
>
> Thanks Duncan. I don't understand your warning, but.
>
> If I call foo(y ~ x,data=xxx) I want the generic to dispatch to the
> formula method.  That method will then look for y and x first in xxx,
> and if it can't find them there it then will look for them in the global
> environment.
>
> If I call foo(x,y,data=xxx) I want the generic to dispatch to the
> default method, irrespective of whether x exists in the global
> environment.  I can't figure out how to arrange this.  As before
> (if I could arrange for the dispatch to happen as desired) I would want
> the method to look for y and x first in xxx, and if it can't find them
> there it then will look for them in the global environment.
>
> It doesn't matter there is an "x" in both xxx and in the global
> environment; the methods will/should use the "x" from xxx.
>
> I don't see a problem with respect to this issue.
>
> Whatever.  I can't get your shoot-in-the-foot solution to work anyway.
>
> If I set
>
> xxx <- data.frame(u=1:10,v=rnorm(10))
>
> and do
>
> foo(x=u,y=v,data=xxx)
>
> I get
>
> > Error in foo.default(x, y, data) : Cannot find x.
>
> The argument names need to match up.  Note that calling foo.default()
> directly works:
>
> foo.default(x=u,y=v,data=xxx)
>
> runs just fine.
>
> I think I'm going to have to give up on the classes-and-methods
> approach.  I *think* I can see a way through with a using a single
> function and if-statements based on your "try" idea.
>
> Thanks!!!
>
> cheers,
>
> Rolf
>
> --
> 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] ISO Code for Namibia ('NA')

2021-09-01 Thread Bill Dunlap
> z <- tibble(Code=c("NA","NZ",NA), Name=c("Namibia","New Zealand","?"))
> z
# A tibble: 3 x 2
  Code  Name
   
1 NANamibia
2 NZNew Zealand
3   ?
> subset(z, Code=="NA")
# A tibble: 1 x 2
  Code  Name
   
1 NANamibia
> subset(z, is.na(Code))
# A tibble: 1 x 2
  Code  Name
   
1   ?
> subset(z, Code==NA_character_)
# A tibble: 0 x 2
# ... with 2 variables: Code , Name 

On Wed, Sep 1, 2021 at 3:33 PM Dr Eberhard Lisse  wrote:

> Hi,
>
> how can I look for the ISO code for Namibia 'NA' in a list of ISO codes
> which looks something like
>
> # A tibble: 10 × 1
>location_code
>
>  1 NC
> [...]
> 10 NZ
>
> but should look like
>
> # A tibble: 10 × 1
>location_code
>
>  1 NA
>  2 NC
> [...]
> 11 NZ
>
> In other words 'NA' is taken for the missing value NA.
>
> greetings, el
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] ggplot error of "`data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class rxlsx"

2021-08-26 Thread Bill Dunlap
The packages "officer" and "readxl" both contain functions named
"read_xlsx".  It looks like you want the one from readxl so refer to it as
readxl::read_xlsx instead of just read_xlsx.

-Bill

On Thu, Aug 26, 2021 at 12:03 PM Kai Yang via R-help 
wrote:

>  Hi all,
> I found something, but I don't know why it happen.
> when I submitted the following code, the Eth is data frame. I can see 14
> obs. of 2 variables
> library(readxl)
> library(ggplot2)
> eth <- read_xlsx("c:/temp/eth.xlsx")
>
>
> but when I add more package (see below,) the Eth is "List of 1"
> library(readxl)
> library(ggplot2)
> library(dplyr)
> library(magrittr)
> library(knitr)
> library(xtable)
> library(flextable)
> library(officer)
> eth <- read_xlsx("c:/temp/eth.xlsx")
>
> But I need those package in future. Is there a way to fix the problem?
> Thanks,
> KaiOn Thursday, August 26, 2021, 11:37:53 AM PDT, Kai Yang via R-help <
> r-help@r-project.org> wrote:
>
>   Hi All,
> 1. the eth is a data frame (not sure that based on error message?) that I
> load it from excel file. Here is the code: eth <-
> read_xlsx("c:/temp/eth.xlsx")
> 2. I try to use the code to convert eth into eth2, but I got error message:
> > eth2 <- data.frame(eth)
> Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors =
> stringsAsFactors) :
>   cannot coerce class ‘"rxlsx"’ to a data.frame
>
> So, it seems the data.frame can not do this data convert? Do you know
> which statement/function can do this?
>
>
> thank you for your help.
>
> On Thursday, August 26, 2021, 09:33:51 AM PDT, Avi Gross via R-help <
> r-help@r-project.org> wrote:
>
>  Kai,
>
> The answer is fairly probable to find  if you examine your variable "eth"
> as that is the only time you are being asked to provide the argument as in
> "ggplot(data=eth, ..) ...)
>
> As the message states, it expects that argument to be a data frame or
> something it can change into a data.frame. What you gave it probably is an
> object meant to represent an EXCEL file or something. You may need to
> extract a data.frame (or tibble or ...) from it before passing that to
> ggplot.
>
> Avi
>
> -Original Message-
> From: R-help  On Behalf Of Kai Yang via
> R-help
> Sent: Thursday, August 26, 2021 11:53 AM
> To: R-help Mailing List 
> Subject: [R] ggplot error of "`data` must be a data frame, or other object
> coercible by `fortify()`, not an S3 object with class rxlsx"
>
> Hello List,
> I got an error message when I submit the code below ggplot(eth,
> aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=ethnicity)) +  geom_rect()
> +  coord_polar(theta="y")  +  xlim(c(2, 4)  )
>
> Error: `data` must be a data frame, or other object coercible by
> `fortify()`, not an S3 object with class rxlsx
>
>
> I checked the syntax. But I can  not find any error on my code. Can you
> help me to find where is the problem?
>
> 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.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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.
>

[[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] split element vector

2021-08-06 Thread Bill Dunlap
unlist(strsplit(vect, "\n"))

On Fri, Aug 6, 2021 at 7:13 AM Luigi Marongiu 
wrote:

> Hello,
> I have a vector that contains some elements with concatenated values, such
> as:
> ```
> > vect
> [1] "name_1"
> [2] "name_2"
> [3] "name_3\nsurname_3"
> [4] "some other text\netc"
> ```
> How can I create a new vector where each component is an element, such as:
> ```
> > vect
> [1] "name_1"
> [2] "name_2"
> [3] "name_3"
> [4] "surname_3"
> [5] "some other text"
> [6] "etc"
> ```
> I can split the elements on '\n' but how do I transfer these directly
> on a new vector?
> Thanks
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] What are the pros and cons of the log.p parameter in (p|q)norm and similar?

2021-08-03 Thread Bill Dunlap
In maximum likelihood problems, even when the individual density values are
fairly far from zero, their product may underflow to zero.  Optimizers have
problems when there is a large flat area.
   > q <- runif(n=1000, -0.1, +0.1)
   > prod(dnorm(q))
   [1] 0
   > sum(dnorm(q, log=TRUE))
   [1] -920.6556

A more minor advantage for some probability-related functions is speed.
E.g., dnorm(log=TRUE,...) does not need to evaluate exp().
   > q <- runif(1e6, -10, 10)
   > system.time(for(i in 1:100)dnorm(q, log=FALSE))
  user  system elapsed
  9.130.119.23
   > system.time(for(i in 1:100)dnorm(q, log=TRUE))
  user  system elapsed
  4.600.194.78

 -Bill

On Tue, Aug 3, 2021 at 11:53 AM Duncan Murdoch 
wrote:

> On 03/08/2021 12:20 p.m., Michael Dewey wrote:
> > Short version
> >
> > Apart from the ability to work with values of p too small to be of much
> > practical use what are the advantages and disadvantages of setting this
> > to TRUE?
> >
> > Longer version
> >
> > I am contemplating upgrading various functions in one of my packages to
> > use this and as far as I can see it would only have the advantage of
> > allowing people to use very small p-values but before I go ahead have I
> > missed anything? I am most concerned with negatives but if there is any
> > other advantage I would mention that in the vignette. I am not concerned
> > about speed or the extra effort in coding and expanding the
> documentation.
> >
>
> These are often needed in likelihood problems.  In just about any
> problem where the normal density shows up in the likelihood, you're
> better off working with the log likelihood and setting log = TRUE in
> dnorm, because sometimes you want to evaluate the likelihood very far
> from its mode.
>
> The same sort of thing happens with pnorm for similar reasons.  Some
> likelihoods involve normal integrals and will need it.
>
> I can't think of an example for qnorm off the top of my head, but I
> imagine there are some:  maybe involving simulation way out in the tails.
>
> The main negative about using logs is that they aren't always needed.
>
> 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] Plotting confidence intervals with ggplot, in multiple facets.

2021-07-19 Thread Bill Dunlap
ggplot2::labs() interprets expressions as plotmath.  E.g.,

   data.frame(X=1:10,Y=(1:10)^2) %>% ggplot(aes(X,Y)) + geom_point() +
   labs(x = expression(beta), y = expression(beta^2))

-Bill


On Mon, Jul 19, 2021 at 4:24 PM Rolf Turner  wrote:

>
>
> Thanks to Jeff Newmiller, Rui Barradas and Avi Gross for their
> extremely helpful replies.  I have got both Jeff's and Rui's code to
> run.  I am currently experimenting with Avi's suggestion of producing
> multiple plots and then putting them together using plotgrid() or
> grid.arrange().  This idea seems to me to be most promising in terms of
> a desideratum that the y-axis scales/limits should be different on the
> two facets.  Also the y-axis labels.
>
> And speaking of y-axis labels:  is it possible in ggplot() to get
> mathematical notation in axis labels, titles and possibly other
> annotation?  (In the manner of plotmath() in base R graphics.)
> Specifically I'd like to get the Greek letters alpha and beta in the
> y-axis labels.  In base R graphics I'd do something like
> ylab=expression(paste("bias in ",beta)) .  Is there an appropriate
> analogue in ggplot()?  (I think that I may have asked this question
> before, some time back, but have forgotten the answer.)
>
> cheers,
>
> Rolf
>
> P.S.  The following is kind of apropos of nothing, but it might serve as
> a useful warning to others of a Trap for Young Players.  I nearly went
> mad (madder?) for a very long time when trying to get Rui's code to run.
> I kept getting errors of the form:
>
> > Error in source("scr.Rui") : scr.Rui:6:2: unexpected input
> > 5: ggplot(eg, aes(Ndat, estimate)) +
> > 6:
> > ^
>
> Took me an unconscionably long while to figure out what was going on.
> I could not see why Jeff's code ran without problem, while Rui's (which
> was very similar) fell over.  Turns out the second character in the
> offending line is a non-printing character, the 160th member of the
> ASCII character set. (It can be produced using "\u00A0".)  Apparently
> this is a "non-breaking space". Whatever that means.  It does NOT get
> treated as white space in the usual way, and triggers the foregoing
> error.
>
> Presumably this invisible character got introduced, into the code that
> Rui emailed, by one of the (many!) infuriating idiosyncrasies of
> Windoze.  Yet another reason, among the many millions of such, not to
> use Windoze.
>
> R.
>
> --
> 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] How to create a matrix from a list without a for loop

2021-07-09 Thread Bill Dunlap
Try
   matrix(init_l, nrow=4, ncol=4,
dimnames=list(c("X1","X2","X3","X4"),c("X1","X2","X3","X4")))
It doesn't give exactly what your code does, but your code introduces an
extra level of "list", which you may not want.

-Bill

On Fri, Jul 9, 2021 at 10:40 AM Laurent Rhelp  wrote:

> Dear R-Help-list,
>
>I have a list init_l containing 16 dataframes and I want to create a
> matrix 4 x 4 from this list with a dataframe in every cell of the
> matrix. I succeeded to do that but my loop is very uggly (cf. below).
> Could somebody help me to write nice R code to do this loop ?
>
> Thank you very much
>
> Laurent
>
>
> ##
> ## mock data, 16 dataframes in a list
> ##
> init_l <- lapply( seq(1,16) , function(x) {
>data.frame( V1 = rnorm(3),
>V2 = rnorm(3),
>V3 = rnorm(3)
>  )
> })
>
> ##
> ## lists matrix creation with n = 4 columns and n = 4 rows
> ##
> n <- 4
> ## an example of row to create the matrix with lists in the cells
> one_row <- rbind( rep( list(rep(list(1),3)) , n) )
> mymat <- do.call( "rbind" , rep( list(one_row) , n) )
>
> ##
> ## The UGGLY loop I would like to improve:
> ##
>
> ## populate the matrix
> k <- 1
> for( i in 1:n){
>for( j in 1:n){
>  mymat[i,j][[1]] <- list( init_l[[ k ]] )
>  k <- k+1
>}
> }
>
> colnames(mymat) <- c("X1", "X2", "X3", "X3")
> rownames(mymat) <- c("X1", "X2", "X3", "X4")
>
>
> mymat
>
> # X1 X2 X3 X3
> # X1 List,1 List,1 List,1 List,1
> # X2 List,1 List,1 List,1 List,1
> # X3 List,1 List,1 List,1 List,1
> # X4 List,1 List,1 List,1 List,1
>
>
> #
> # verification, it works
> #
> mymat[2,2]
> init_l[[6]]
>
> ##
> init_l[[6]]
>
> library(tidyverse)
> mymat.t <- as.tibble(mymat)
> mymat.t
> unnest(mymat.t[2,2],cols="X2")[[1]][[1]]
>
> mymat.df <- as.data.frame(mymat)
> mymat.df[2,2][[1]][[1]]
>
>
> thx
>
>
>
> --
> L'absence de virus dans ce courrier électronique a été vérifiée par le
> logiciel antivirus 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] List / Matrix to Data Frame

2021-07-01 Thread Bill Dunlap
Does this do what you want?

> df <- data.frame(check.names=FALSE,
lapply(c(Date="date",netIncome="netIncome",`Gross Profit`="grossProfit"),
function(nm)vapply(ISY, "[[", nm, FUN.VALUE=NA_character_)))
> str(df)
'data.frame':   36 obs. of  3 variables:
 $ Date: chr  "2020-09-30" "2019-09-30" "2018-09-30" "2017-09-30"
...
 $ netIncome   : chr  "5741100.00" "5525600.00" "5953100.00"
"4835100.00" ...
 $ Gross Profit: chr  "10495600.00" "9839200.00" "10183900.00"
"8818600.00" ...
> df$Date <- as.Date(df$Date)
> df$netIncome <- as.numeric(df$netIncome)
> df$`Gross Profit` <- as.numeric(df$`Gross Profit`)
> str(df)
'data.frame':   36 obs. of  3 variables:
 $ Date: Date, format: "2020-09-30" "2019-09-30" "2018-09-30"
"2017-09-30" ...
 $ netIncome   : num  5.74e+10 5.53e+10 5.95e+10 4.84e+10 4.57e+10 ...
 $ Gross Profit: num  1.05e+11 9.84e+10 1.02e+11 8.82e+10 8.43e+10 ...
> with(df, plot(Date, netIncome))

On Thu, Jul 1, 2021 at 5:35 PM Sparks, John  wrote:

> Hi R-Helpers,
>
> I am taking it upon myself to delve into the world of lists for R.  In no
> small part because I appear to have discovered a source of data for an
> exceptionally good price but that delivers much of that data in json format.
>
> So over the last day or so I managed to fight the list processing tools to
> a draw and get a list that has only selected elements (actually it ends up
> in matrix form).  But when I try to convert that to a data frame I can't
> get it to a form that is workable.
>
> I have visited some pages about converting a matrix to a data frame but
> they result in highly redundant and inelegant data.
>
> I am thinking that someone who works with lists and matrices knows how to
> do this quite easily and would be willing to provide a solution.
>
> The reproducible example is shown below.  Just to be explicit, what I am
> trying to get to is something along the lines of a data frame like this.
>
> Date  netIncome  Gross Profit
> 2020-09-30 5741100 10495600
> 2019-09-30 5525600   9839200
>
> .
>
> The closest I get is a matrix that looks like this
>
> > wanted
> 2020-09-302019-09-30   2018-09-30
> 2017-09-30   2016-09-30   2015-09-30   2014-09-30
> date"2020-09-30"  "2019-09-30" "2018-09-30"
> "2017-09-30" "2016-09-30" "2015-09-30" "2014-09-30"
> netIncome   "5741100.00"  "5525600.00" "5953100.00"
> "4835100.00" "4568700.00" "5339400.00" "3951000.00"
> grossProfit "10495600.00" "9839200.00" "10183900.00"
> "8818600.00" "8426300.00" "9362600.00" "7053700.00"
>
> Code for example
>
> library(jsonlite)
> test <- jsonlite::fromJSON("
> https://eodhistoricaldata.com/api/fundamentals/AAPL.US?api_token=OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX
> ")
>
> hist<-test[[13]]
> ISY<-hist$Income_Statement$yearly
> wanted<-sapply(ISY, "[", j = c("date","netIncome","grossProfit"))
>
>
> Your guidance would be much appreciated.
>
> --John J. Sparks, Ph.D.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Special characters in cell names

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

-Bill

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

> Hi
> I have a column in my data file which is "X/Y". With '/' I want to
> emphasize that values are the ratio of X over Y.
> Problem is that in the following command for a violin plot, I am not able
> to specify that '/' even with double quotes.
>
> p <- ggplot(mydata, aes(x=W, y="X/Y")) + geom_violin(trim=FALSE)
>
> However, if I change that column to "Y" and use
>
> p <- ggplot(mydata, aes(x=W, y=Y)) + geom_violin(trim=FALSE)
>
> Then the plot will be correctly shown.
> Any ideas for that?
>
> Regards,
> Mahmood
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


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

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

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

-Bill

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

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

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

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

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

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

-Bill

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

> I make the same mistake all over again.
>
> In particular, suppose we have:
>
> a = c(1,2,3,4,5)
>
> and a variable that equals 1 for the elements I want to select:
>
> t = c(1,1,1,0,0)
>
> To select the first 3 elements.
>
> The problem is that
>
> a[t]
>
> would repeat the first element 3 times .
>
> I have to either convert `t` to boolean:
>
> a[t==1]
>
> Or use `which`
>
> a[which(t==1)]
>
> How can I "spot" this error?
>
> It often happens in long scripts.
>
> Do I have to check the type each time?
>
> Do you have any suggestions?
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Read fst files

2021-06-09 Thread Bill Dunlap
Try using unzip(zipfile, files="desiredFile", exdir=tf<-tempfile()), not
unz(zipfile, "desiredFile"), to copy the desired file from the zip file to
a temporary location and use read_fst(tf) to read the desired file.

-Bill

On Wed, Jun 9, 2021 at 11:27 AM Jeff Reichman 
wrote:

> Jan
>
> Makes sense. Its just that I often receive  large zip files that contain a
> variety of file types.
>
> Jef
>
> -Original Message-
> From: R-help  On Behalf Of Jan van der Laan
> Sent: Wednesday, June 9, 2021 12:56 PM
> To: r-help@r-project.org
> Subject: Re: [R] Read fst files
>
>
>
> read_fst is from the package fst. The fileformat fst uses is a binary
> format designed to be fast readable. It is a column  oriented format and
> compressed. So, to be able to work fst needs access to the file itself
> and wont accept a file connection as functions like read.table an
> variants accept.
>
> Also, because it is a binary compressed format using a compression
> method that is fast to read, compressing also to zip seems to defeat the
> purpose of fst.
>
> HTH,
> Jan
>
>
> On 09-06-2021 15:28, Duncan Murdoch wrote:
> > On 09/06/2021 9:12 a.m., Jeff Reichman wrote:
> >> Duncan
> >>
> >> Yea that will work. It appears to be related to setting my working
> >> dir, for what ever reason neither seem to work
> >> (1) knitr::opts_knit$set(root.dir
> >> ="~/My_Reference_Library/Regression") # from R Notebook or
> >> (2)
> >> setwd("C:/Users/reichmaj/Documents/My_Reference_Library/Regression") #
> >> from R chunk
> >>
> >> So it appears I can either (as you suggested) use two steps or combine
> >> but I need to enter the full path. Why other file types don't seem to
> >> need the full path ?
> >
> > You need to read the documentation for read_fst() to find what it needs.
> >   If it doesn't explain this, then you should report the issue to its
> > author.
> >
> >>
> >> myObject <-
> >>
> read_fst(unz("C:/Users/reichmaj/Documents/My_Reference_Library/Regression/Datasest.zip",
>
> >> filename = "myFile.fst"))
> >>
> >> Thank you. I guess just one of those R things
> >
> > No, it's a read_fst() thing.
> >
> > Duncan Murdoch
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] Beginner problem - using mod function to print odd numbers

2021-06-09 Thread Bill Dunlap
Martin wrote
  Use
  num[num %% 2 == 1]
  instead of much slower and ...@#^$
  num[ifelse(num %% 2 == 1, TRUE, FALSE)]

Read the '[' as 'such that' when the subscript is logical
(=="Boolean"==TRUE/FALSE-values).

[The original post had a typo/thinko, num<-num+i instead of num<-num+1,
which was simply an error, not a matter of style.  R's vectorization makes
it easy to avoid such errors.]

-Bill

On Wed, Jun 9, 2021 at 2:56 AM Martin Maechler 
wrote:

> >>>>> David Carlsonon Sun, 6 Jun 2021 15:21:34 -0400 writes:
>
> > There is really no need for a loop:
> > num <- 1:100
> > num[ifelse(num %% 2 == 1, TRUE, FALSE)]
>
> > [1]  1  3  5  7  9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45
> 47 49
> > [26] 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93
> 95 97 99
>
> Well, and the above "works" but is really another proof of my
> year-long claim that people use  ifelse(.)  *MUCH MUCH* too often,
> and should really learn to use alternatives, in this case,
> "R 101" (*long* before fooverse):
>
> Use
>
> num[num %% 2 == 1]
>
> instead of much slower and ...@#^$
>
> num[ifelse(num %% 2 == 1, TRUE, FALSE)]
>
> Martin Maechler
> ETH Zurich
>
> > On Sat, Jun 5, 2021 at 2:05 PM William Michels via R-help
> >  wrote:
> >>
> >> > i <- 1L; span <- 1:100; result <- NA;
> >> > for (i in span){
> >> + ifelse(i %% 2 != 0, result[i] <- TRUE, result[i] <- FALSE)
> >> + }
> >> > span[result]
> >> [1]  1  3  5  7  9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41
> 43
>
>  []
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/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] About Pearson correlation functions

2021-05-30 Thread Bill Dunlap
You didn't say how the values differed.  If one in the plot is a rounded
version of the other then adding the ggpur::ggscatter() argument
   cor.coeff.args=list(digits=7)
will fix things up.

-Bill

On Sun, May 30, 2021 at 9:18 AM Mahmood Naderan-Tahan <
mahmood.nade...@ugent.be> wrote:

> Hi
>
> Maybe this is not directly related to R, but I appreciate you can help me
> with an idea. I use the following ggscatter function to plot a Pearson
> correlation Coefficient and it works fine. In the chart I see both R-value
> and P-value.
>
>
> ggscatter(mydata, x = "V1", y = "V2", add = "reg.line", conf.int =
> TRUE, cor.coef = TRUE, cor.method = "pearson")
>
>
> On the other hand, when I use this command
>
>
> res <- cor.test(mydata$V1, mydata$V2, method = "pearson")
>
>
> The R and P values are different from ggscatter.
>
>
> I would like to know:
>
>
> 1- Why they are different?
>
> 2- How to print P and R values of ggscatter on terminal?
>
>
>
> Regards,
> Mahmood
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] No error message but don't get the 8 graphs

2021-05-10 Thread Bill Dunlap
Also, normalizePath("power.pdf").

On Sun, May 9, 2021 at 5:13 PM Bert Gunter  wrote:

> ?getwd
>
> 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, May 9, 2021 at 2:59 PM varin sacha via R-help <
> r-help@r-project.org>
> wrote:
>
> > Rui,
> >
> > The created pdf.file is off-screen device. Indeed after dev.off() I
> should
> > view the pdf file on my computer. But I don't find it. Where do I find
> the
> > pdf.file ?
> >
> > Regards,
> >
> >
> >
> > Le dimanche 9 mai 2021 à 22:44:22 UTC+2, Rui Barradas <
> > ruipbarra...@sapo.pt> a écrit :
> >
> >
> >
> >
> >
> > Hello,
> >
> > You are not closing the pdf device.
> > The only changes I have made to your code are right at the beginning of
> > the plotting instructions and at the end of the code.
> >
> >
> > ## The rest of the code is for plotting the image
> > pdf(file = "power.pdf")
> > op <- par(mfrow = c(4,2), cex = 0.45)
> >
> > [...]
> >
> > par(op)
> > dev.off()
> > #
> >
> > The comments only line is your last code line.
> > The result is attached.
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > Às 19:39 de 09/05/21, varin sacha via R-help escreveu:
> > > Dear R-experts,
> > >
> > > I am trying to get the 8 graphs like the ones in this paper :
> > > https://statweb.stanford.edu/~tibs/reshef/comment.pdf
> > > My R code does not show any error message neither warnings but I d'on't
> > get what I would like to get (I mean the 8 graphs), so I am missing
> > something. What's it ? Many thanks for your precious help.
> > >
> > > #
> > > set.seed(1)
> > > library(energy)
> > >
> > > # Here we define parameters which we use to simulate the data
> > > # The number of null datasets we use to estimate our rejection reject
> > #regions for an alternative with level 0.05
> > > nsim=50
> > >
> > > # Number of alternative datasets we use to estimate our power
> > > nsim2=50
> > >
> > > # The number of different noise levels used
> > > num.noise <- 30
> > >
> > > # A constant to determine the amount of noise
> > > noise <- 3
> > >
> > > # Number of data points per simulation
> > > n=100
> > >
> > > # Vectors holding the null "correlations" (for pearson, for spearman,
> > for kendall and dcor respectively) for each # of the nsim null datasets
> at
> > a #given noise level
> > > val.cor=val.cors=val.cork=val.dcor=rep(NA,nsim)
> > >
> > > # Vectors holding the alternative "correlations" (for pearson, for
> > #spearman, for kendall and dcor respectively) #for each of the nsim2
> > alternative datasets at a given noise level
> > > val.cor2=val.cors2=val.cork2=val.dcor2= rep(NA,nsim2)
> > >
> > >
> > > # Arrays holding the estimated power for each of the 4 "correlation"
> > types, for each data type (linear, #parabolic, etc...) with each noise
> level
> > > power.cor=power.cors=power.cork=power.dcor= array(NA, c(8,num.noise))
> > >
> > > ## We loop through the noise level and functional form; each time we
> > #estimate a null distribution based on #the marginals of the data, and
> then
> > #use that null distribution to estimate power
> > > ## We use a uniformly distributed x, because in the original paper the
> > #authors used the same
> > >
> > > for(l in 1:num.noise) {
> > >
> > >for(typ in 1:8) {
> > >
> > > ## This next loop simulates data under the null with the correct
> > marginals (x is uniform, and y is a function of a #uniform with gaussian
> > noise)
> > >
> > >  for(ii in 1:nsim) {
> > >x=runif(n)
> > >
> > > #lin+noise
> > > if(typ==1) {
> > > y=x+ noise *(l/num.noise)* rnorm(n)
> > > }
> > >
> > > #parabolic+noise
> > > if(typ==2) {
> > > y=4*(x-.5)^2+  noise * (l/num.noise) * rnorm(n)
> > > }
> > >
> > > #cubic+noise
> > > if(typ==3) {
> > > y=128*(x-1/3)^3-48*(x-1/3)^3-12*(x-1/3)+10* noise  * (l/num.noise)
> > *rnorm(n)
> > > }
> > >
> > > #sin+noise
> > > if(typ==4) {
> > > y=sin(4*pi*x) + 2*noise * (l/num.noise) *rnorm(n)
> > > }
> > >
> > > #their sine + noise
> > > if(typ==5) {
> > > y=sin(16*pi*x) + noise * (l/num.noise) *rnorm(n)
> > > }
> > >
> > > #x^(1/4) + noise
> > > if(typ==6) {
> > > y=x^(1/4) + noise * (l/num.noise) *rnorm(n)
> > > }
> > >
> > > #circle
> > > if(typ==7) {
> > > y=(2*rbinom(n,1,0.5)-1) * (sqrt(1 - (2*x - 1)^2)) + noise/4*l/num.noise
> > *rnorm(n)
> > > }
> > >
> > > #step function
> > > if(typ==8) {
> > > y = (x > 0.5) + noise*5*l/num.noise *rnorm(n)
> > > }
> > >
> > > # We resimulate x so that we have the null scenario
> > > x <- runif(n)
> > >
> > > # Calculate the 4 correlations
> > > val.cor[ii]=(cor(x,y))
> > > val.cors[ii]=(cor(x,y,method=c("spearman")))
> > > val.cork[ii]=(cor(x,y,method=c("kendal")))
> > > val.dcor[ii]=dcor(x,y)
> > > }
> > >
> > > ## Next we calculate our 4 rejection cutoffs
> > > cut.cor=quantile(val.cor,.95)
> > > cut.cors=quantile(val.cors,.95)
> > > cut.cork=quantile(val.cork,.95)
> > > 

Re: [R] R versions > 4.0.2 fail to start in Windows 64-bit

2021-04-21 Thread Bill Dunlap
Does this happen when you start R with the --vanilla flag?  When you remove
or rename ./.RData?

-Bill

On Tue, Apr 20, 2021 at 8:37 PM N. Jordan Jameson 
wrote:

> I have a 64-bit Windows machine and I've installed R versions 4.0.0 through
> 4.0.5 and only versions 4.0.2 and below will successfully start. This
> morning I installed 4.0.5, and when I start R, the R-gui starts for less
> than a second and then disappears. I tried to open R using RStudio and I
> got the following messages:
>
> `The R session failed to start.` and ` The R session process exited with
> code -1073740791`
>
> The log for this error is:
>
> ```
> ERROR system error 10053 (An established connection was aborted by the
> software in your host machine) [request-uri: /events/get_events];
>
> OCCURRED AT void __thiscall rstudio::session::HttpConnectionImpl rstudio_boost::asio::ip::tcp>::sendResponse(const class
> rstudio::core::http::Response &)
> src/cpp/session/http/SessionWin32HttpConnectionListener.cpp:113;
>
> LOGGED FROM: void __thiscall rstudio::session::HttpConnectionImpl rstudio_boost::asio::ip::tcp>::sendResponse(const class
> rstudio::core::http::Response &)
> src/cpp/session/http/SessionWin32HttpConnectionListener.cpp:118
> ```
> I'm not sure what is going on, but this same thing happens with R 4.0.3 and
> R 4.0.4, but not with R 4.0.2. I would like to use the most recent version
> of R if possible, but for now I am stuck with 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.


Re: [R] Bug? Index output of C functions R_qsort_I and R_qsort_int_I is not modified

2021-04-15 Thread Bill Dunlap
R_ext/Utils.h:void R_qsort_int_I(int *iv, int *II, int i, int j);

The last 2 arguments are int, not int*.  .C() passes pointers to vectors so
you cannot call this function directly from .C().

-Bill

On Thu, Apr 15, 2021 at 3:15 PM Evangelos Evangelou via R-help <
r-help@r-project.org> wrote:

> Hi all.
>
> Reading the documentation of these two functions
>
> https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Utility-functions
> "The ..._I() versions also return the sort.index() vector in I."
> I can't find anything in the documentation about sort.index(), but I'm
> guessing that I is the index that makes the input sorted, as in R's
> order(). However running the following code on
> R version 4.0.5 (2021-03-31) Platform: x86_64-pc-linux-gnu (64-bit)
> does not give me that. It just gives me the original input.
>
> Rlib = file.path(Sys.getenv("R_HOME"), "lib", paste0("libR",
> .Platform$dynlib.ext))
> dyn.load(Rlib)
> n = 4L
> ix = n:1
> i = integer(n)
> cc = .C("R_qsort_int_I", ix, i, 1L, n)
> cc[[2]]
>
> I expect 4 3 2 1, but I get 0 0 0 0. Is this a bug or have I misunderstood
> something?
>
> Best,
> Vangelis
>
> [[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] evil attributes

2021-04-11 Thread Bill Dunlap
Terry wrote
   I confess to being puzzled WHY the R core has decided on this
definition [of vector] ...
I believe that "R core" followed S's definition of "vector".  From the
beginning (at least when I first saw it in 1981) an S vector was the basic
unit of an S object - it had a type and a length and no more.  This has
little to do with the mathematician's or physicist's notion of a vector.
It is more like what Technopedia (
https://www.techopedia.com/definition/22817/vector-programming) says is a
programmer's notion of a vector:

What Does Vector Mean?
A vector, in programming, is a type of array that is one dimensional.
Vectors are a logical element in programming languages that are used for
storing data. Vectors are similar to arrays but their actual implementation
and operation differs.
Techopedia Explains Vector
Vectors are primarily used within the programming context of most
programming languages and serve as data structure containers. Being a data
structure, vectors are used for storing objects and collections of objects
in an organized structure.
The major difference between and array and a vector is that, unlike typical
arrays, the container size of a vector can be easily increased and
decreased to complement different data storage types. Vectors have a
dynamic structure and provide the ability to assign container size up front
and enable allocation of memory space quickly. Vectors can be thought of as
dynamic arrays.

-Bill


On Sun, Apr 11, 2021 at 8:04 AM Therneau, Terry M., Ph.D. via R-help <
r-help@r-project.org> wrote:

> I wrote: "I confess to being puzzled WHY the R core has decided on this
> definition..."
> After just a little more thought let me answer my own question.
>
> a. The as.vector() function is designed to strip off everything extraneous
> and leave just
> the core.   (I have a mental image of Jack Webb saying "Just the facts
> ma'am").   I myself
> use it freqently in the test suite for survival, in cases where I'm
> checking the corrent
> numeric result and don't care about any attached names.
>
>   b. is.vector(x) essentially answers the question "does x look like a
> result of as.vector?"
>
> Nevertheless I understand Roger's confusion.
>
> --
> Terry M Therneau, PhD
> Department of Quantitative Health Sciences
> Mayo Clinic
> thern...@mayo.edu
>
> "TERR-ree THUR-noh"
>
>
> [[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] Violin plot with mean_sdl

2021-04-01 Thread Bill Dunlap
help(stat_summary) suggests you use the fun.args=list(...) argument to
pass arguments to the fun.* functions.   Try replacing mult=1 by
fun.args=list(mult=1).

It is possible that ggplot2::stat_summary changed its behavior since
that web page was written or that the web page was always wrong.

-Bill

On Wed, Mar 31, 2021 at 11:03 PM Mahmood Naderan-Tahan
 wrote:
>
> Hi,
>
> I followed the example described at [1] but I don't know why I get the 
> following warning
>
>
> > library(ggplot2)
> > library(Hmisc)
> > mydata <- read.csv('test.csv', header=T,row.names=1)
> > mydata
>  V1  V2   V3 V4
> P1 73.6 0.7 74.6  R
> P2 75.2 0.7 75.8  R
> P3  6.5 0.0  7.3  R
> P4 41.4 0.3 39.2  C
> P5  5.4 0.1 18.2  C
> P6 18.8 0.3 30.3  C
> > p <- ggplot(mydata, aes(x=V4, y=V1)) + geom_violin(trim=FALSE)
> > p + stat_summary(fun.data="mean_sdl", mult=1,
> +  geom="crossbar", width=0.2 )
> Warning message:
> Ignoring unknown parameters: mult
>
>
> How can I fix that?
>
>
>
> [1] 
> http://www.sthda.com/english/wiki/ggplot2-violin-plot-quick-start-guide-r-software-and-data-visualization
>
>
> Regards,
> Mahmood
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] "for" loop does not work with my plot_ly command

2021-03-30 Thread Bill Dunlap
Printing the return value of plot_ly and friends works for me in the
following examples:
# make base plot
p0 <- plotly::plot_ly(na.omit(palmerpenguins::penguins), x =
~bill_length_mm, y = ~body_mass_g)
# now add things to base plot
for(vrbl in list(~species, ~island, ~year)) {
   tmp <- plotly::add_markers(p0, symbol=vrbl, color=vrbl)
   print(tmp)
}
# or, the put the plots in a list
plots <- lapply(list(~species, ~island, ~year), function(vrbl)
plotly::add_markers(p0, symbol=vrbl, color=vrbl))
print(plots)



On Tue, Mar 30, 2021 at 2:26 AM Rachida El Ouaraini
 wrote:
>
> Hi Mika,
> and thank you very much for your answer.
> When I add the "for" loop to the code that produces before the graph I
> want, it does nothing :
> NO graph and NO error message.
> It seems to me that the command plot_ly and the for loop DO NOT coexist.
>
> Rachida
>
> On Mon, Mar 29, 2021 at 7:44 PM Mika Hamari 
> wrote:
>
> > Hi!
> >
> >
> >
> > I am also learning, but I want try to help. I often use for-loop in R. I
> > think that it could be due to dimensions of CPM, not the structure of the
> > loop.
> >
> >
> >
> > What kind of error message do you get? Is it: ”incorrect number of
> > dimensions”? What happens if you substitute in the end instead of CPM[i,1]
> > this:
> >
> >
> >
> > file.copy("C:/Users/pc/Downloads/Evolution Tmoy.png",
> > paste("C:/MONOGRAPHIE/Resultats/Evolution Tmoy_",CPM[i],".png",sep="")
> >
> >
> >
> > *Lähettäjä: *Rachida El Ouaraini 
> > *Lähetetty: *maanantai 29. maaliskuuta 2021 18.15
> > *Vastaanottaja: *r-help@r-project.org
> > *Aihe: *[R] "for" loop does not work with my plot_ly command
> >
> >
> >
> > Hi everyone,
> > I am new to R programming, and I am having difficulties modifying an R
> > script to introduce the "for" loop in the code.
> > While searching I found that this issue has already been raised, but I did
> > not know what to do to fix mine !
> >
> > *The code that works (without for command):*
> >
> > CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
> > ",", skip = 0)
> > # The CPM.txt file containe 1 line
> > ..
> > ..
> > options(viewer = NULL)
> > plot_ly() %>%
> >  htmlwidgets::onRender(
> >"function(el, x) {
> >  var gd = document.getElementById(el.id);
> >  Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
> > filename: 'AnomalieRR_EcartTmoy'});
> >}"
> >  )%>%
> >  add_trace(x =TAnn[ ,3],  y = TAnn[ ,5], name = "Normale mensuelle de
> > Tmax(en °C)",type = 'scatter', mode = 'markers',  marker = list(size = T,
> > symbol = 'circle',  color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
> > %>%
> > add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
> > list(color = "white", size = 14),  showarrow = FALSE)%>%
> >  layout(title = paste("Combinaison anomalie relative annuelle des
> > précipitations et écart annuel à la normale de la température moyenne  à
> > ",CPM[1,1],sep =""),
> >   xaxis = list(title = "Anomalie relative des précipitations
> > annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
> > , family = 'Arial'), tickfont = list(color = "blue", size = 14)),
> > yaxis = list(title = "Ecart à la normale de la température moyenne
> > annuelle(en°C)", titlefont = list(color= "red", size= 14 , family =
> > 'Arial'),
> > tickfont = list(color = "red", size = 14) , showline = TRUE, linecolor =
> > "red", linewidth = 2),
> >legend = list(x = 0.1, y = -0.3, font=list(size = 14,color=
> > "black")),margin = list(
> >   t = 70,
> >  r = 70,
> >   b = 70,
> >   l = 70
> > ))
> > *The code that does not work (with for command):*
> > CPM <- read.table("FicConfig/CPM.txt" , header = TRUE, sep = "\t" , dec =
> > ",", skip = 0)
> > # The CPM.txt file containe several lines
> >
> > *for (i in 1: (nrow(CPM)))   {*
> >
> > options(viewer = NULL)
> > plot_ly() %>%
> >  htmlwidgets::onRender(
> >"function(el, x) {
> >  var gd = document.getElementById(el.id);
> >  Plotly.downloadImage(gd, {format: 'png', width: 1000, height: 700,
> > filename: 'AnomalieRR_EcartTmoy'});
> >}"
> >  )%>%
> >  add_trace(x =TAnn[ ,3],  y = TAnn[ ,5], name = "Normale mensuelle de
> > Tmax(en °C)",type = 'scatter', mode = 'markers',  marker = list(size = T,
> > symbol = 'circle',  color = ~TAnn[ ,5], line = list(width= 2, color = cl)))
> > %>%
> > add_annotations(text = TAnn[ ,1], x= TAnn[ ,3], y = TAnn[ ,5], font =
> > list(color = "white", size = 14),  showarrow = FALSE)%>%
> >   layout(title = paste("Combinaison anomalie relative annuelle des
> > précipitations et écart annuel à la normale de la température moyenne  à
> > ",CPM[i,1],sep =""),
> >   xaxis = list(title = "Anomalie relative des précipitations
> > annuelles(en %)", tickangle = 20 ,titlefont = list(color= "blue", size= 14
> > , family = 'Arial'), tickfont = list(color = 

Re: [R] Colorizing different individuals with fviz

2021-03-29 Thread Bill Dunlap
That error means that fviz_famd_ind has more than one argument that
starts with 'col' and you must type a more complete name to
disambiguate it.  Perhaps col.ind=ifelse(...)?

> args(factoextra::fviz_famd_ind)
function (X, axes = c(1, 2), geom = c("point", "text"),
repel = FALSE, habillage = "none", palette = NULL,
addEllipses = FALSE, col.ind = "blue", col.ind.sup = "darkblue",
alpha.ind = 1, shape.ind = 19, col.quali.var = "black",
select.ind = list(name = NULL, cos2 = NULL, contrib = NULL),
gradient.cols = NULL, ...)

On Mon, Mar 29, 2021 at 2:20 PM Mahmood Naderan-Tahan
 wrote:
>
> Hi Jim,
>
> It seems that the following proposed method doesn't work
>
>
> ind <- get_famd_ind(res.famd)
> fviz_famd_ind(res.famd,
>   col=ifelse(x>10,"red","black"),
>   repel = TRUE)
>
>
> Result is:
>
>
> Error in fviz_famd_ind(res.famd, col = ifelse(x > 10, "red", "black"),  :
>   argument 2 matches multiple formal arguments
>
>
>
> Any idea to fix that?
>
> Regards,
> Mahmood
>
> 
> From: Jim Lemon 
> Sent: Saturday, March 27, 2021 9:19:23 PM
> To: Mahmood Naderan-Tahan
> Cc: r-help@r-project.org
> Subject: Re: [R] Colorizing different individuals with fviz
>
> Hi Mahmood,
> What you have specified can be done with:
>
> col=c(rep("black",10),rep("red",10))
>
> depending upon what print function you are using. I suspect that this
> may be based on a value in your data. For example, if you want  black
> for values of some variable up to 10 and red for those over:
>
> col=ifelse(x>10,"red","black)
>
> Jim
>
> On Sun, Mar 28, 2021 at 12:20 AM Mahmood Naderan-Tahan
>  wrote:
> >
> > Hi
> >
> > I use this command to generate a graph of individuals
> >
> >
> > ind <- get_famd_ind(res.famd)
> > fviz_famd_ind(res.famd, repel = TRUE)
> >
> >
> > I would like to know how can I specify different colors for different 
> > individuals?
> >
> > The colorization is not very complex. Basically, I want to specify 
> > rows[1:10] to be shown in black and rows[11:20] to be shown in red.
> >
> >
> > Any idea about that?
> >
> >
> > Regards,
> > Mahmood
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] local maxima positions in a vector with duplicated values

2021-03-29 Thread Bill Dunlap
Your original query included
> x <- c(1,0,0,0,2,2,3,4,0,1,1,0,5,5,5,0,1)
... I need 8 10 13.
Did you also want the 1's at the ends to count as local maxima,
so the result would be c(1,8,10,13,17)?
Or do you want the maxima at endpoints only if there are no others?

-BIll

On Mon, Mar 29, 2021 at 8:56 AM Stefano Sofia
 wrote:
>
> Thank you Bill, your tip solved everything.
>
> Stefano
>
>  (oo)
> --oOO--( )--OOo--
> Stefano Sofia PhD
> Civil Protection - Marche Region - Italy
> Meteo Section
> Snow Section
> Via del Colle Ameno 5
> 60126 Torrette di Ancona, Ancona (AN)
> Uff: +39 071 806 7743
> E-mail: stefano.so...@regione.marche.it
> ---Oo-oO----
>
> 
> Da: Bill Dunlap [williamwdun...@gmail.com]
> Inviato: lunedì 29 marzo 2021 17.22
> A: Stefano Sofia
> Cc: bgunter.4...@gmail.com; minsh...@umich.edu; r-help mailing list
> Oggetto: Re: [R] local maxima positions in a vector with duplicated values
>
> If you want to accept maxima at the ends of the series, append -Inf to
> each end and subtract one from the result.  Note that this will make
> even a constant sequence have a local maximum at 1.
>
> On Mon, Mar 29, 2021 at 6:52 AM Stefano Sofia
>  wrote:
> >
> > Dear Bill, Bert, Greg and Abby,
> > I tested your code (honestly apart from Abby's solution because it needed 
> > an additional package and I run R in a server which is not administrated by 
> > myself), they work and I found them equivalent. (Probably Bill's and Greg's 
> > solutions are a bit faster than Bert's.)
> >
> > In my real application I found a case where none of them work: when the 
> > series is monotonic. In this case the last number of the vector (or the 
> > last duplicated numbers) is not a maximum but it is anyway the highest 
> > number of the vector:
> >
> > >x <- c(1,1,1,2,2,3,4,4,4,5,6,6,6)
> >
> > The error is: argument is of length zero.
> > Your code is at the moment too complicated for me to modify. I ask if there 
> > is an "easy" extension of the code that you kindly wrote for me to handle 
> > also this possibility.
> >
> > Thank you for everything
> > Stefano
> >
> >
> >
> >  (oo)
> > --oOO--( )--OOo--
> > Stefano Sofia PhD
> > Civil Protection - Marche Region - Italy
> > Meteo Section
> > Snow Section
> > Via del Colle Ameno 5
> > 60126 Torrette di Ancona, Ancona (AN)
> > Uff: +39 071 806 7743
> > E-mail: stefano.so...@regione.marche.it
> > ---Oo-oO
> >
> > 
> > Da: Bill Dunlap [williamwdun...@gmail.com]
> > Inviato: venerdì 26 marzo 2021 18.40
> > A: Stefano Sofia
> > Cc: r-help mailing list
> > Oggetto: Re: [R] local maxima positions in a vector with duplicated values
> >
> > Using rle() may make it easier - finding the peak values is easier and
> > select from cumsum(lengths) to get the positions of the last values
> > before the peaks, then add 1.  I have not tested the following very
> > much.
> >
> > function(x) {
> >   rx <- rle(x)
> >   cumsum(rx$lengths)[c(diff(diff(rx$values)>0) == -1,FALSE,FALSE)]+1
> > }
> >
> > -Bill
> >
> > On Fri, Mar 26, 2021 at 8:36 AM Stefano Sofia
> >  wrote:
> > >
> > > Dear list users,
> > > I need to find local maxima and local minima positions in a vector where 
> > > there might be duplicates; in the particular in case of
> > > - duplicated local maxima, I should take the position of the first 
> > > duplicated value;
> > > - duplicated local minima, I should take the position of the last 
> > > duplicated value.
> > >
> > > Example:
> > >
> > > >x <- c(1,0,0,0,2,2,3,4,0,1,1,0,5,5,5,0,1)
> > > >which(diff(diff(x)>=0)<0)+1
> > >
> > > gives me 8 11 15 while I need 8 10 13;
> > >
> > > >which(diff(diff(x)>0)>0)+1
> > >
> > > gives me 4 6  9 12 16 while I need 4 9 12 16.
> > >
> > > Could you please help me in this task? I would be happier not to use 
> > > additional packages.
> > >
> > > Thank you for your precious help
> > > Stefano
> > >
> > >
> > >  (oo)
> > > --oOO--( )--OOo--
> > > Stefano Sofia PhD
> 

Re: [R] seed problem?

2021-03-29 Thread Bill Dunlap
Does this happen if you start R with the --vanilla flag?  If so it may
be that you have a startup file, .\.Rprofile or %HOME%\.Rprofile that
is calling set.seed(n) for a fixed n.

-Bill

On Mon, Mar 29, 2021 at 12:16 AM Mika Hamari  wrote:
>
> Hi!
>
> I have Windows 10 on PC and different versions of R. I noticed that when I 
> executed simulation with R 4.0.3, it gave exactly the same results next time 
> when I re-opened the program. I didn’t set the seed.
>
> I tested this also with simple ”rnorm(10,100,10)”, and the results were every 
> time the same, when I re-opened the program. It seems that it starts with the 
> same seed. R 4.0.0 and 4.0.3 did it, both with 32- and 64-bit versions. But 
> with R Studio the results were every time different, as they were also 
> different with 3.4.3. This explains, why I hadn’t noticed this earlier.
>
> I know the function set.seed(), but I wonder, how in the first place seed can 
> be every time same, if you don’t set it to be. What I read about seeds, this 
> should be very highly improbable occurence.
>
> Thanks to all developers for what they are doing for common good. I love R!
>
> Mika Hamari
>
> [[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] local maxima positions in a vector with duplicated values

2021-03-29 Thread Bill Dunlap
If you want to accept maxima at the ends of the series, append -Inf to
each end and subtract one from the result.  Note that this will make
even a constant sequence have a local maximum at 1.

On Mon, Mar 29, 2021 at 6:52 AM Stefano Sofia
 wrote:
>
> Dear Bill, Bert, Greg and Abby,
> I tested your code (honestly apart from Abby's solution because it needed an 
> additional package and I run R in a server which is not administrated by 
> myself), they work and I found them equivalent. (Probably Bill's and Greg's 
> solutions are a bit faster than Bert's.)
>
> In my real application I found a case where none of them work: when the 
> series is monotonic. In this case the last number of the vector (or the last 
> duplicated numbers) is not a maximum but it is anyway the highest number of 
> the vector:
>
> >x <- c(1,1,1,2,2,3,4,4,4,5,6,6,6)
>
> The error is: argument is of length zero.
> Your code is at the moment too complicated for me to modify. I ask if there 
> is an "easy" extension of the code that you kindly wrote for me to handle 
> also this possibility.
>
> Thank you for everything
> Stefano
>
>
>
>  (oo)
> --oOO--( )--OOo--
> Stefano Sofia PhD
> Civil Protection - Marche Region - Italy
> Meteo Section
> Snow Section
> Via del Colle Ameno 5
> 60126 Torrette di Ancona, Ancona (AN)
> Uff: +39 071 806 7743
> E-mail: stefano.so...@regione.marche.it
> ---Oo-oO
>
> 
> Da: Bill Dunlap [williamwdun...@gmail.com]
> Inviato: venerdì 26 marzo 2021 18.40
> A: Stefano Sofia
> Cc: r-help mailing list
> Oggetto: Re: [R] local maxima positions in a vector with duplicated values
>
> Using rle() may make it easier - finding the peak values is easier and
> select from cumsum(lengths) to get the positions of the last values
> before the peaks, then add 1.  I have not tested the following very
> much.
>
> function(x) {
>   rx <- rle(x)
>   cumsum(rx$lengths)[c(diff(diff(rx$values)>0) == -1,FALSE,FALSE)]+1
> }
>
> -Bill
>
> On Fri, Mar 26, 2021 at 8:36 AM Stefano Sofia
>  wrote:
> >
> > Dear list users,
> > I need to find local maxima and local minima positions in a vector where 
> > there might be duplicates; in the particular in case of
> > - duplicated local maxima, I should take the position of the first 
> > duplicated value;
> > - duplicated local minima, I should take the position of the last 
> > duplicated value.
> >
> > Example:
> >
> > >x <- c(1,0,0,0,2,2,3,4,0,1,1,0,5,5,5,0,1)
> > >which(diff(diff(x)>=0)<0)+1
> >
> > gives me 8 11 15 while I need 8 10 13;
> >
> > >which(diff(diff(x)>0)>0)+1
> >
> > gives me 4 6  9 12 16 while I need 4 9 12 16.
> >
> > Could you please help me in this task? I would be happier not to use 
> > additional packages.
> >
> > Thank you for your precious help
> > Stefano
> >
> >
> >  (oo)
> > --oOO--( )--OOo--
> > Stefano Sofia PhD
> > Civil Protection - Marche Region - Italy
> > Meteo Section
> > Snow Section
> > Via del Colle Ameno 5
> > 60126 Torrette di Ancona, Ancona (AN)
> > Uff: +39 071 806 7743
> > E-mail: stefano.so...@regione.marche.it
> > ---Oo-oO
> >
> > 
> >
> > AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
> > informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
> > alla ricezione. I messaggi di posta elettronica per i client di Regione 
> > Marche possono contenere informazioni confidenziali e con privilegi legali. 
> > Se non si è il destinatario specificato, non leggere, copiare, inoltrare o 
> > archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, 
> > inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio 
> > computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in 
> > caso di necessità ed urgenza, la risposta al presente messaggio di posta 
> > elettronica può essere visionata da persone estranee al destinatario.
> > IMPORTANT NOTICE: This e-mail message is intended to be received only by 
> > persons entitled to receive the confidential information it may contain. 
> > E-mail messages to clients of Regione Marche may contain information that 
> > is confidential and legally privileged. Please do not read, copy, forward, 
> > or

Re: [R] local maxima positions in a vector with duplicated values

2021-03-26 Thread Bill Dunlap
Using rle() may make it easier - finding the peak values is easier and
select from cumsum(lengths) to get the positions of the last values
before the peaks, then add 1.  I have not tested the following very
much.

function(x) {
  rx <- rle(x)
  cumsum(rx$lengths)[c(diff(diff(rx$values)>0) == -1,FALSE,FALSE)]+1
}

-Bill

On Fri, Mar 26, 2021 at 8:36 AM Stefano Sofia
 wrote:
>
> Dear list users,
> I need to find local maxima and local minima positions in a vector where 
> there might be duplicates; in the particular in case of
> - duplicated local maxima, I should take the position of the first duplicated 
> value;
> - duplicated local minima, I should take the position of the last duplicated 
> value.
>
> Example:
>
> >x <- c(1,0,0,0,2,2,3,4,0,1,1,0,5,5,5,0,1)
> >which(diff(diff(x)>=0)<0)+1
>
> gives me 8 11 15 while I need 8 10 13;
>
> >which(diff(diff(x)>0)>0)+1
>
> gives me 4 6  9 12 16 while I need 4 9 12 16.
>
> Could you please help me in this task? I would be happier not to use 
> additional packages.
>
> Thank you for your precious help
> Stefano
>
>
>  (oo)
> --oOO--( )--OOo--
> Stefano Sofia PhD
> Civil Protection - Marche Region - Italy
> Meteo Section
> Snow Section
> Via del Colle Ameno 5
> 60126 Torrette di Ancona, Ancona (AN)
> Uff: +39 071 806 7743
> E-mail: stefano.so...@regione.marche.it
> ---Oo-oO
>
> 
>
> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
> informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
> alla ricezione. I messaggi di posta elettronica per i client di Regione 
> Marche possono contenere informazioni confidenziali e con privilegi legali. 
> Se non si è il destinatario specificato, non leggere, copiare, inoltrare o 
> archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, 
> inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio 
> computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso 
> di necessità ed urgenza, la risposta al presente messaggio di posta 
> elettronica può essere visionata da persone estranee al destinatario.
> IMPORTANT NOTICE: This e-mail message is intended to be received only by 
> persons entitled to receive the confidential information it may contain. 
> E-mail messages to clients of Regione Marche may contain information that is 
> confidential and legally privileged. Please do not read, copy, forward, or 
> store this message unless you are an intended recipient of it. If you have 
> received this message in error, please forward it to the sender and delete it 
> completely from your computer system.
>
> --
> Questo messaggio  stato analizzato da Libraesva ESG ed  risultato non infetto.
> This message was scanned by Libraesva ESG and is believed to be clean.
>
>
> [[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] Optimization function producing negative parameter values

2021-03-21 Thread Bill Dunlap
Does optim go out of bounds when you specify hessian=FALSE?
hessian=TRUE causes some out-of-bounds evaluations of f.

> optim(c(X=1,Y=1), 
> function(XY){print(unname(XY));(XY[["X"]]+1)^4+(XY[["Y"]]-2)^4}, method= 
> "L-BFGS-B", lower=c(0.001,0.001), upper=c(1.5,1.5), hessian=TRUE)
[1] 1 1
[1] 1.001 1.000
[1] 0.999 1.000
[1] 1.000 1.001
[1] 1.000 0.999
[1] 0.001 1.500
[1] 0.002 1.500
[1] 0.001 1.500
[1] 0.001 1.500
[1] 0.001 1.499
[1] 0.003 1.500
[1] 0.001 1.500
[1] 0.002 1.501
[1] 0.002 1.499
[1] 0.001 1.500
[1] -0.001  1.500
[1] 0.000 1.501
[1] 0.000 1.499
[1] 0.002 1.501
[1] 0.000 1.501
[1] 0.001 1.502
[1] 0.001 1.500
[1] 0.002 1.499
[1] 0.000 1.499
[1] 0.001 1.500
[1] 0.001 1.498
$par
X Y
0.001 1.500

$value
[1] 1.066506

On Sun, Mar 21, 2021 at 10:22 AM Shah Alam  wrote:
>
> Dear all,
>
> I am using optim() to estimate unknown parameters by minimizing the
> residual sums of squares. I created a function with the model. The model is
> working fine. The optim function is producing negative parameter values, even
> I have introduced upper and lower bounds (given in code). Therefore,
> the model produces *NAs*.
>
> Following is my code.
>
> param <<- c(0.002,0.002, 0.14,0.012,0.01,0.02, 0.03, 0.001)# initial
> > parameter values
> > opt <- optim(param, fn= f.opt, obsdata =obsdata_1, method= "L-BFGS-B",
> > lower = c(0.001, 0.001, 0.08,0.008, 0.009, 0.008, 0.009, 0.001),
>
> upper = c(0.00375, 0.002, 0.2, 0.018, 0.08, 0.08, 0.08, 0.01),
> > control=list(maxit=10), hessian = T)
>
>
> Error:
>
> *"NAs producedError in if (rnd_1 < liferisk) { : missing value where
> TRUE/FALSE needed "*
>
> The model function which produces NA due to negative parameter values
>
> liferisk <- rnorm(n = 1, mean =
> (calib_para[which(names(calib_para)=="r_mu")]),sd =
> (calib_para[which(names(calib_para)=="r_sd")]))
>
>   rnd_1 <- runif(1, 0, 1)
>
>   if (rnd_1 < liferisk) { ca_case <- 1} else {ca_case <- 0}
>
>
> How to design/ modify optim() function, and upper-lower bounds to stop
> producing negative values during parameter search?
> Thanks
>
> Best regards,
> Shah
>
> [[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] library(hms)

2021-03-17 Thread Bill Dunlap
install.packages("hms")

A 'library' is a directory (aka folder) that contains installed
'packages'.  I.e., one installs packages into a library, but one does
not install a library.

-Bill

On Wed, Mar 17, 2021 at 10:08 AM Gregory Coats via R-help
 wrote:
>
> On my MacBook, I do not have, and do not know how to install, library(hms).
> Greg Coats
>
> > library(hms)
> Error in library(hms) : there is no package called ‘hms’
> > Install.libraries(“hms”)
> Error: unexpected input in "Install.libraries(“"
> >
> [[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] help

2021-03-16 Thread Bill Dunlap
The length of the mean vector must match the number of rows and
columns of the sigma matrix.  Once you give 3 entries in the mean
vector you will run into the problem that the sigma you are using is
not positive (semi-)definite - a variance must be the product of a
matrix and its transpose.

-Bill

On Tue, Mar 16, 2021 at 10:55 AM hatice gürdil
 wrote:
>
> Code a is working. But code b is given error like given below. How can I
> write code b?
>
> > a<-rmvnorm(750, mean=c(0, 0),
> +sigma=matrix(c(1, .3, .3, 1), ncol=2))
>
> > head(a)
> [,1][,2]
> [1,] -0.97622921 -0.87129405
> [2,]  0.54763494  0.16080131
> [3,] -1.16627647  0.31225125
> [4,]  1.72541168  2.06513939
> [5,]  0.05372489 -0.07525197
> [6,] -0.85062230 -1.02188473
>
> > b<-rmvnorm(round(500,0), mean=c(0,-1),
> +sigma=matrix(c(.3, 1,1,1,.3, 1, 1,1, .3), ncol=3))
>
> Error in rmvnorm(round(500, 0), mean = c(0, -1), sigma = matrix(c(0.3,  :
>   mean and sigma have non-conforming size
>
> [[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] Failure in predicting parameters

2021-03-14 Thread Bill Dunlap
> rutledge_param <- function(p, x, y) ((p$M / (1 + exp(-1*(p$x-p$m)/p$s))) + 
> p$B) - y

Did you mean that p$x to be just x?  As is, this returns numeric(0)
for the p that nls.lm gives it because p$x is NULL and NULL-aNumber is
numeric().

-Bill

On Sun, Mar 14, 2021 at 9:46 AM Luigi Marongiu  wrote:
>
> Hello,
> I would like to use the Rutledge equation
> (https://pubmed.ncbi.nlm.nih.gov/15601990/) to model PCR data. The
> equation is:
> Fc = Fmax / (1+exp(-(C-Chalf)/k)) + Fb
> I defined the equation and another that subtracts the values from the
> expectations. I used minpack.lm to get the parameters, but I got an
> error:
> ```
>
> > library("minpack.lm")
> > h <- c(120.64, 66.14, 34.87, 27.11, 8.87, -5.8, 4.52, -7.16, -17.39,
> +-14.29, -20.26, -14.99, -21.05, -20.64, -8.03, -21.56, -1.28, 15.01,
> +75.26, 191.76, 455.09, 985.96, 1825.59, 2908.08, 3993.18, 5059.94,
> +6071.93, 6986.32, 7796.01, 8502.25, 9111.46, 9638.01, 10077.19,
> +10452.02, 10751.81, 11017.49, 11240.37, 11427.47, 11570.07, 11684.96,
> +11781.77, 11863.35, 11927.44, 11980.81, 12021.88, 12058.35, 12100.63,
> +12133.57, 12148.89, 12137.09)
> > high <- h[1:45]
> > MaxFluo <- max(high)
> > halfFluo <- MaxFluo/2
> > halfCycle = 27
> > find_slope <- function(X, Y) {
> +   Slope <- c(0)
> +   for (i in 2:length(X)) {
> + delta_x <- X[i] - X[i-1]
> + delta_y <- Y[i] - Y[i-1]
> + Slope[i] <- delta_y/delta_x
> +   }
> +   return(Slope)
> + }
> > slopes <- find_slope(1:45, high)
> >
> > rutledge <- function(m, s, M, B, x) {
> +   divisor = 1 + exp(-1* ((x-m)/s) )
> +   y = (M/divisor) + B
> +   return(y)
> + }
> > rutledge_param <- function(p, x, y) ((p$M / (1 + exp(-1*(p$x-p$m)/p$s))) + 
> > p$B) - y
> >
> >
> > init = rutledge(halfFluo, slopes, MaxFluo, 0, high)
> > points(1:45, init, type="l", col="red")
> > estim <- nls.lm(par = list(m = halfFluo, s = slopes, M = MaxFluo, B = 
> > high[1]),
> + fn = rutledge_param, x = 1:45, y = high)
> Error in nls.lm(par = list(m = halfFluo, s = slopes, M = MaxFluo, B =
> high[1]),  :
>   evaluation of fn function returns non-sensible value!
> ```
>
> Where could the error be?
>
>
> --
> Best regards,
> Luigi
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Warning messages while parallel computing

2021-03-04 Thread Bill Dunlap
Perhaps just try
source("xx.R")
invisible(gc()) # do warnings appear after this?
It does seem likely that the sourced file causes the problem, since
parallel::createCluster labels the connections ":" and that label would show up in the warning.

On Thu, Mar 4, 2021 at 11:28 AM Henrik Bengtsson
 wrote:
>
> Test with:
>
> clusterCall(cl, function() { suppressWarnings(source("xx.R")) })
>
> If the warnings disappear, then the warnings are produced on the
> workers from source():ing the file.
>
> /Henrik
>
> On Thu, Mar 4, 2021 at 10:20 AM Bill Dunlap  wrote:
> >
> > The warnings come from the garbage collector, which may be called from
> > almost anywhere.  It is possible that the file that is sourced causes
> > the problem, but if you don't call parallel::stopCluster before
> > removing the cluster object you will get those warnings.
> >
> > > cl <- parallel::makeCluster(3, type="PSOCK")
> > > invisible(gc())
> > > rm(cl)
> > > invisible(gc())
> > Warning messages:
> > 1: In .Internal(gc(verbose, reset, full)) :
> >   closing unused connection 6 (<-Bill-T490:11216)
> > 2: In .Internal(gc(verbose, reset, full)) :
> >   closing unused connection 5 (<-Bill-T490:11216)
> > 3: In .Internal(gc(verbose, reset, full)) :
> >   closing unused connection 4 (<-Bill-T490:11216)
> > >
> > >
> > > cl <- parallel::makeCluster(3, type="PSOCK")
> > > invisible(gc())
> > > parallel::stopCluster(cl)
> > > invisible(gc())
> > > rm(cl)
> > > invisible(gc())
> > >
> >
> > The fact that he got 8 warnings when playing a cluster of size 8 makes
> > me suspect that omitting stopCluster is the problem.
> >
> > -Bill
> >
> > On Thu, Mar 4, 2021 at 10:12 AM Henrik Bengtsson
> >  wrote:
> > >
> > > I don't think 'parallel' is to blame in this case. Those warnings:
> > >
> > > Warning in for (i in seq_len(Ne + echo)) { :
> > >   closing unused connection 19
> > >
> > > come from base::source()
> > > [https://github.com/wch/r-source/blob/9caddc1eaad1f480283f1e98af34a328699d1869/src/library/base/R/source.R#L166-L244].
> > >
> > > Unless there's a bug in source() that leaves connections open, which
> > > is unlikely, I think there's something in the 'xx.R' script that opens
> > > a connection but doesn't close it.  Possibly multiple times.  A good
> > > check is to see if the same warnings are produced when calling
> > > source("xx.R") sequentially in a for() loop or an lapply() call.
> > >
> > > Hope this helps,
> > >
> > > Henrik
> > >
> > > On Thu, Mar 4, 2021 at 9:58 AM Bill Dunlap  
> > > wrote:
> > > >
> > > > To avoid the warnings from gc(), call parallel::stopCluster(cl) before
> > > > removing or overwriting cl.
> > > >
> > > > -Bill
> > > >
> > > > On Thu, Mar 4, 2021 at 1:52 AM Shah Alam  
> > > > wrote:
> > > > >
> > > > > Hello everyone,
> > > > >
> > > > > I am using the "parallel" R package for parallel computation.
> > > > >
> > > > > Code:
> > > > >
> > > > ># set number of cores
> > > > > cl <- makeCluster(8, type = "PSOCK")  # Mac/Linux need to set as 
> > > > > "FORK"
> > > > >
> > > > >   # pass functions and objects to the cluster environment and set 
> > > > > seed
> > > > >   # all the items exported need to stay in the global 
> > > > > environment!!
> > > > >   clusterCall(cl, function() { source("xx.R" )})
> > > > >   clusterExport(cl, list("a", "b", "c", "d",
> > > > >  "5"))
> > > > >   clusterSetRNGStream(cl, 1)
> > > > >
> > > > > While parallel processing, I receive the following warning signs.  Do 
> > > > > I
> > > > > need to ignore these signs or do they potentially slow the whole 
> > > > > process?
> > > > >
> > > > >  *  Warning signs:*
> > > > > Warning in for (i in seq_len(Ne + echo)) { :
> > > > >

Re: [R] Warning messages while parallel computing

2021-03-04 Thread Bill Dunlap
The warnings come from the garbage collector, which may be called from
almost anywhere.  It is possible that the file that is sourced causes
the problem, but if you don't call parallel::stopCluster before
removing the cluster object you will get those warnings.

> cl <- parallel::makeCluster(3, type="PSOCK")
> invisible(gc())
> rm(cl)
> invisible(gc())
Warning messages:
1: In .Internal(gc(verbose, reset, full)) :
  closing unused connection 6 (<-Bill-T490:11216)
2: In .Internal(gc(verbose, reset, full)) :
  closing unused connection 5 (<-Bill-T490:11216)
3: In .Internal(gc(verbose, reset, full)) :
  closing unused connection 4 (<-Bill-T490:11216)
>
>
> cl <- parallel::makeCluster(3, type="PSOCK")
> invisible(gc())
> parallel::stopCluster(cl)
> invisible(gc())
> rm(cl)
> invisible(gc())
>

The fact that he got 8 warnings when playing a cluster of size 8 makes
me suspect that omitting stopCluster is the problem.

-Bill

On Thu, Mar 4, 2021 at 10:12 AM Henrik Bengtsson
 wrote:
>
> I don't think 'parallel' is to blame in this case. Those warnings:
>
> Warning in for (i in seq_len(Ne + echo)) { :
>   closing unused connection 19
>
> come from base::source()
> [https://github.com/wch/r-source/blob/9caddc1eaad1f480283f1e98af34a328699d1869/src/library/base/R/source.R#L166-L244].
>
> Unless there's a bug in source() that leaves connections open, which
> is unlikely, I think there's something in the 'xx.R' script that opens
> a connection but doesn't close it.  Possibly multiple times.  A good
> check is to see if the same warnings are produced when calling
> source("xx.R") sequentially in a for() loop or an lapply() call.
>
> Hope this helps,
>
> Henrik
>
> On Thu, Mar 4, 2021 at 9:58 AM Bill Dunlap  wrote:
> >
> > To avoid the warnings from gc(), call parallel::stopCluster(cl) before
> > removing or overwriting cl.
> >
> > -Bill
> >
> > On Thu, Mar 4, 2021 at 1:52 AM Shah Alam  wrote:
> > >
> > > Hello everyone,
> > >
> > > I am using the "parallel" R package for parallel computation.
> > >
> > > Code:
> > >
> > ># set number of cores
> > > cl <- makeCluster(8, type = "PSOCK")  # Mac/Linux need to set as 
> > > "FORK"
> > >
> > >   # pass functions and objects to the cluster environment and set seed
> > >   # all the items exported need to stay in the global environment!!
> > >   clusterCall(cl, function() { source("xx.R" )})
> > >   clusterExport(cl, list("a", "b", "c", "d",
> > >  "5"))
> > >   clusterSetRNGStream(cl, 1)
> > >
> > > While parallel processing, I receive the following warning signs.  Do I
> > > need to ignore these signs or do they potentially slow the whole process?
> > >
> > >  *  Warning signs:*
> > > Warning in for (i in seq_len(Ne + echo)) { :
> > >   closing unused connection 19
> > > Warning in for (i in seq_len(Ne + echo)) { :
> > >   closing unused connection 18
> > > Warning in for (i in seq_len(Ne + echo)) { :
> > >   closing unused connection 17
> > > Warning in for (i in seq_len(Ne + echo)) { :
> > >   closing unused connection 16
> > > Warning in for (i in seq_len(Ne + echo)) { :
> > >   closing unused connection 15
> > > Warning in for (i in seq_len(Ne + echo)) { :
> > >   closing unused connection 14
> > > Warning in for (i in seq_len(Ne + echo)) { :
> > >   closing unused connection 13
> > > Warning in for (i in seq_len(Ne + echo)) { :
> > >   closing unused connection 12
> > >
> > > Best regards,
> > > Shah Alam
> > >
> > > [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide 
> > > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Warning messages while parallel computing

2021-03-04 Thread Bill Dunlap
To avoid the warnings from gc(), call parallel::stopCluster(cl) before
removing or overwriting cl.

-Bill

On Thu, Mar 4, 2021 at 1:52 AM Shah Alam  wrote:
>
> Hello everyone,
>
> I am using the "parallel" R package for parallel computation.
>
> Code:
>
># set number of cores
> cl <- makeCluster(8, type = "PSOCK")  # Mac/Linux need to set as "FORK"
>
>   # pass functions and objects to the cluster environment and set seed
>   # all the items exported need to stay in the global environment!!
>   clusterCall(cl, function() { source("xx.R" )})
>   clusterExport(cl, list("a", "b", "c", "d",
>  "5"))
>   clusterSetRNGStream(cl, 1)
>
> While parallel processing, I receive the following warning signs.  Do I
> need to ignore these signs or do they potentially slow the whole process?
>
>  *  Warning signs:*
> Warning in for (i in seq_len(Ne + echo)) { :
>   closing unused connection 19
> Warning in for (i in seq_len(Ne + echo)) { :
>   closing unused connection 18
> Warning in for (i in seq_len(Ne + echo)) { :
>   closing unused connection 17
> Warning in for (i in seq_len(Ne + echo)) { :
>   closing unused connection 16
> Warning in for (i in seq_len(Ne + echo)) { :
>   closing unused connection 15
> Warning in for (i in seq_len(Ne + echo)) { :
>   closing unused connection 14
> Warning in for (i in seq_len(Ne + echo)) { :
>   closing unused connection 13
> Warning in for (i in seq_len(Ne + echo)) { :
>   closing unused connection 12
>
> Best regards,
> Shah Alam
>
> [[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] print and coef Methods for survreg Differ

2021-02-23 Thread bill
How should you be able to make a prediction (using this type of model) from a 
state where there is no data such as treatment="C" in my example?

-Original Message-
From: Jeff Newmiller  
Sent: Tuesday, February 23, 2021 11:10 AM
To: r-help@r-project.org; b...@denney.ws
Subject: Re: [R] print and coef Methods for survreg Differ

Model equations do not normally have conditional forms dependent on whether 
specific coefficients are NA or not. If you assign NA to a coefficient then you 
will not be able to predict outputs for input cases that you should be able to. 
Zero allows these expected cases to work... NA would prevent any useful 
prediction output.

On February 23, 2021 6:45:53 AM PST, b...@denney.ws wrote:
>Hello,
>
> 
>
>I'm working on a survreg model where the full data are subset for 
>modeling individual parts of the data separately.  When subsetting, the 
>fit variable ("treatment" in the example below) has levels that are not 
>in the data.
> A
>work-around for this is to drop the levels, but it seems inaccurate to 
>have the `coef()` method provide zero as the coefficient for the level 
>without data.
>
> 
>
>Why does coef(model) provide zero as the coefficient for treatment 
>instead of NA?  Is this a bug?
>
> 
>
>Thanks,
>
> 
>
>Bill
>
> 
>
>``` r
>
>library(survival)
>
>library(emmeans)
>
> 
>
>my_data <-
>
>  data.frame(
>
>value=c(rep(1, 5), 6:10),
>
>treatment=factor(rep(c("A", "B"), each=5), levels=c("A", "B", "C"))
>
>  )
>
>my_data$cens <- c(0, 1)[(my_data$value == 1) + 1]
>
> 
>
>model <- survreg(Surv(time=value, event=cens)~treatment, data=my_data)
>
>#> Warning in survreg.fit(X, Y, weights, offset, init = init, 
>controlvals =
>
>#> control, : Ran out of iterations and did not converge
>
>coef(model)
>
>#> (Intercept)  treatmentB  treatmentC
>
>#>  0.08588218  2.40341893  0.
>
>model$coef
>
>#> (Intercept)  treatmentB  treatmentC
>
>#>  0.08588218  2.40341893  NA
>
>model$coefficients
>
>#> (Intercept)  treatmentB  treatmentC
>
>#>  0.08588218  2.40341893  0.
>
>print(model)
>
>#> Call:
>
>#> survreg(formula = Surv(time = value, event = cens) ~ treatment,
>
>#> data = my_data)
>
>#>
>
>#> Coefficients: (1 not defined because of singularities)
>
>#> (Intercept)  treatmentB  treatmentC
>
>#>  0.08588218  2.40341893  NA 
>
>#>
>
>#> Scale= 0.09832254
>
>#>
>
>#> Loglik(model)= 4.9   Loglik(intercept only)= -15
>
>#>  Chisq= 39.92 on 2 degrees of freedom, p= 2.15e-09
>
>#> n= 10
>
>summary(model)
>
>#>
>
>#> Call:
>
>#> survreg(formula = Surv(time = value, event = cens) ~ treatment,
>
>#> data = my_data)
>
>#>   Value Std. Error z  p
>
>#> (Intercept)  0.0859 0.0681  1.26   0.21
>
>#> treatmentB   2.4034 0.2198 10.93 <2e-16
>
>#> treatmentC   0. 0.NA NA
>
>#> Log(scale)  -2.3195 0.  -Inf <2e-16
>
>#>
>
>#> Scale= 0.0983
>
>#>
>
>#> Weibull distribution
>
>#> Loglik(model)= 4.9   Loglik(intercept only)= -15
>
>#>  Chisq= 39.92 on 2 degrees of freedom, p= 2.1e-09
>
>#> Number of Newton-Raphson Iterations: 30
>
>#> n= 10
>
>ref_grid(model)
>
>#> Error in ref_grid(model): Something went wrong:
>
>#>  Non-conformable elements in reference grid.
>
> 
>
>my_data_correct_levels <- my_data
>
>my_data_correct_levels$treatment <-
>droplevels(my_data_correct_levels$treatment)
>
> 
>
>model_correct <- survreg(Surv(time=value, event=cens)~treatment,
>data=my_data_correct_levels)
>
>#> Warning in survreg.fit(X, Y, weights, offset, init = init, 
>controlvals =
>
>#> control, : Ran out of iterations and did not converge
>
>coef(model_correct)
>
>#> (Intercept)  treatmentB
>
>#>  0.08588218  2.40341893
>
>print(model_correct)
>
>#> Call:
>
>#> survreg(formula = Surv(time = value, event = cens) ~ treatment,
>
>#> data = my_data_correct_levels)
>
>#>
>
>#> Coefficients:
>
>#> (Intercept)  treatmentB
>
>#>  0.08588218  2.40341893
>
>#>
>
>#> Scale= 0.09832254
>
>#>
>
>#> Loglik(model)= 4.9   Loglik(intercept only)= -15
>
>#>  Chisq= 39.92 on 1 degrees of freedom, p= 2.65e-10
>
>#> n= 10
>
>summary(model_correct)
>
>#>
>
>#&

[R] print and coef Methods for survreg Differ

2021-02-23 Thread bill
Hello,

 

I'm working on a survreg model where the full data are subset for modeling
individual parts of the data separately.  When subsetting, the fit variable
("treatment" in the example below) has levels that are not in the data.  A
work-around for this is to drop the levels, but it seems inaccurate to have
the `coef()` method provide zero as the coefficient for the level without
data.

 

Why does coef(model) provide zero as the coefficient for treatment instead
of NA?  Is this a bug?

 

Thanks,

 

Bill

 

``` r

library(survival)

library(emmeans)

 

my_data <-

  data.frame(

value=c(rep(1, 5), 6:10),

treatment=factor(rep(c("A", "B"), each=5), levels=c("A", "B", "C"))

  )

my_data$cens <- c(0, 1)[(my_data$value == 1) + 1]

 

model <- survreg(Surv(time=value, event=cens)~treatment, data=my_data)

#> Warning in survreg.fit(X, Y, weights, offset, init = init, controlvals =

#> control, : Ran out of iterations and did not converge

coef(model)

#> (Intercept)  treatmentB  treatmentC 

#>  0.08588218  2.40341893  0.

model$coef

#> (Intercept)  treatmentB  treatmentC 

#>  0.08588218  2.40341893  NA

model$coefficients

#> (Intercept)  treatmentB  treatmentC 

#>  0.08588218  2.40341893  0.

print(model)

#> Call:

#> survreg(formula = Surv(time = value, event = cens) ~ treatment, 

#> data = my_data)

#> 

#> Coefficients: (1 not defined because of singularities)

#> (Intercept)  treatmentB  treatmentC 

#>  0.08588218  2.40341893  NA 

#> 

#> Scale= 0.09832254 

#> 

#> Loglik(model)= 4.9   Loglik(intercept only)= -15

#>  Chisq= 39.92 on 2 degrees of freedom, p= 2.15e-09 

#> n= 10

summary(model)

#> 

#> Call:

#> survreg(formula = Surv(time = value, event = cens) ~ treatment, 

#> data = my_data)

#>   Value Std. Error z  p

#> (Intercept)  0.0859 0.0681  1.26   0.21

#> treatmentB   2.4034 0.2198 10.93 <2e-16

#> treatmentC   0. 0.NA NA

#> Log(scale)  -2.3195 0.  -Inf <2e-16

#> 

#> Scale= 0.0983 

#> 

#> Weibull distribution

#> Loglik(model)= 4.9   Loglik(intercept only)= -15

#>  Chisq= 39.92 on 2 degrees of freedom, p= 2.1e-09 

#> Number of Newton-Raphson Iterations: 30 

#> n= 10

ref_grid(model)

#> Error in ref_grid(model): Something went wrong:

#>  Non-conformable elements in reference grid.

 

my_data_correct_levels <- my_data

my_data_correct_levels$treatment <-
droplevels(my_data_correct_levels$treatment)

 

model_correct <- survreg(Surv(time=value, event=cens)~treatment,
data=my_data_correct_levels)

#> Warning in survreg.fit(X, Y, weights, offset, init = init, controlvals =

#> control, : Ran out of iterations and did not converge

coef(model_correct)

#> (Intercept)  treatmentB 

#>  0.08588218  2.40341893

print(model_correct)

#> Call:

#> survreg(formula = Surv(time = value, event = cens) ~ treatment, 

#> data = my_data_correct_levels)

#> 

#> Coefficients:

#> (Intercept)  treatmentB 

#>  0.08588218  2.40341893 

#> 

#> Scale= 0.09832254 

#> 

#> Loglik(model)= 4.9   Loglik(intercept only)= -15

#>  Chisq= 39.92 on 1 degrees of freedom, p= 2.65e-10 

#> n= 10

summary(model_correct)

#> 

#> Call:

#> survreg(formula = Surv(time = value, event = cens) ~ treatment, 

#> data = my_data_correct_levels)

#>   Value Std. Error z  p

#> (Intercept)  0.0859 0.0681  1.26   0.21

#> treatmentB   2.4034 0.2198 10.93 <2e-16

#> Log(scale)  -2.3195 0.  -Inf <2e-16

#> 

#> Scale= 0.0983 

#> 

#> Weibull distribution

#> Loglik(model)= 4.9   Loglik(intercept only)= -15

#>  Chisq= 39.92 on 1 degrees of freedom, p= 2.6e-10 

#> Number of Newton-Raphson Iterations: 30 

#> n= 10

ref_grid(model_correct)

#> 'emmGrid' object with variables:

#> treatment = A, B

#> Transformation: "log"

```

 

Created on 2021-02-23 by the [reprex
package](https://reprex.tidyverse.org) (v1.0.0)


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

2021-02-22 Thread Bill Dunlap
You said the column values were separated by space characters.
Copying the text from gmail shows that some column names and column
values are separated by single spaces (e.g., between x1 and x2) and
some by multiple spaces (e.g., between x3 and x4.  Did the mail mess
up the spacing or is there some other way to tell where the omitted
values are?

-Bill

On Mon, Feb 22, 2021 at 2:54 PM Val  wrote:
>
> I Tried that one and it did not work. Please see the error message
> Error in read.table(text = "x1  x2  x3 x4\n1 B12 \n2   C23
> \n322 B32  D34 \n4D44 \n51 D53\n60 D62 ",
> :
>   more columns than column names
>
> On Mon, Feb 22, 2021 at 5:39 PM Bill Dunlap  wrote:
> >
> > Since the columns in the file are separated by a space character, " ",
> > add the read.table argument sep=" ".
> >
> > -Bill
> >
> > On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
> > >
> > > Hi all, I am trying to read a messy data  but facing  difficulty.  The
> > > data has several columns separated by blank space(s).  Each column
> > > value may have different lengths across the rows.   The first
> > > row(header) has four columns. However, each row may not have the four
> > > column values.  For instance, the first data row has only the first
> > > two column values. The fourth data row has the first and last column
> > > values, the second and the third column values are missing for this
> > > row..  How do I read this data set correctly? Here is my sample data
> > > set, output and desired output.   To make it clear to each data point
> > > I have added the row and column numbers. I cannot use fixed width
> > > format reading because each row  may have different length for  a
> > > given column.
> > >
> > > dat<-read.table(text="x1  x2  x3 x4
> > > 1 B22
> > > 2 C33
> > > 322 B22  D34
> > > 4 D44
> > > 51 D53
> > > 60 D62",header=T, fill=T,na.strings=c("","NA"))
> > >
> > > Output
> > >   x1  x2 x3 x4
> > > 1   1 B12  NA
> > > 2   2C23   NA
> > > 3 322  B32  D34   NA
> > > 4   4   D44NA
> > > 5  51 D53 NA
> > > 6  60 D62NA
> > >
> > >
> > > Desired output
> > >x1   x2 x3   x4
> > > 1   1B22   NA
> > > 2   2 C33 NA
> > > 3 322  B32NA  D34
> > > 4   4  NA  D44
> > > 5  51D53 NA
> > > 6  60   D62  NA
> > >
> > > 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.

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

2021-02-22 Thread Bill Dunlap
Since the columns in the file are separated by a space character, " ",
add the read.table argument sep=" ".

-Bill

On Mon, Feb 22, 2021 at 2:21 PM Val  wrote:
>
> Hi all, I am trying to read a messy data  but facing  difficulty.  The
> data has several columns separated by blank space(s).  Each column
> value may have different lengths across the rows.   The first
> row(header) has four columns. However, each row may not have the four
> column values.  For instance, the first data row has only the first
> two column values. The fourth data row has the first and last column
> values, the second and the third column values are missing for this
> row..  How do I read this data set correctly? Here is my sample data
> set, output and desired output.   To make it clear to each data point
> I have added the row and column numbers. I cannot use fixed width
> format reading because each row  may have different length for  a
> given column.
>
> dat<-read.table(text="x1  x2  x3 x4
> 1 B22
> 2 C33
> 322 B22  D34
> 4 D44
> 51 D53
> 60 D62",header=T, fill=T,na.strings=c("","NA"))
>
> Output
>   x1  x2 x3 x4
> 1   1 B12  NA
> 2   2C23   NA
> 3 322  B32  D34   NA
> 4   4   D44NA
> 5  51 D53 NA
> 6  60 D62NA
>
>
> Desired output
>x1   x2 x3   x4
> 1   1B22   NA
> 2   2 C33 NA
> 3 322  B32NA  D34
> 4   4  NA  D44
> 5  51D53 NA
> 6  60   D62  NA
>
> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 load fasta file with openPrimeR?

2021-02-15 Thread Bill Dunlap
> but if I give these commands to a local file:
> ```
> fasta.file <- system.file("extdata", "IMGT_data", "templates",
> "stx.fa", package = "openPrimeR")
> fasta.file <- system.file("stx.fa", package = "openPrimeR")
> ```
> where stx.fa il the file I wanted to open and that is present in the
> working directly. I get only an empty object.

If "stx.fa" is in fact in the current working directory then use
   fasta.file <- "stx.fa"
system.file() is for accessing files in installed packages.

-Bill

On Mon, Feb 15, 2021 at 10:11 AM Luigi Marongiu
 wrote:
>
> Hello,
> I am trying to load a fast file with the package 'openPrimeR'. The
> manual 
> (https://www.bioconductor.org/packages/release/bioc/vignettes/openPrimeR/inst/doc/openPrimeR_vignette.html)
> says to use:
> ```
> fasta.file <- system.file("extdata", "IMGT_data", "templates",
> "Homo_sapiens_IGH_functional_exon.fasta", package =
> "openPrimeR")
> # Load the template sequences from 'fasta.file'
> seq.df.simple <- read_templates(fasta.file)
> ```
> but if I give these commands to a local file:
> ```
> fasta.file <- system.file("extdata", "IMGT_data", "templates",
> "stx.fa", package = "openPrimeR")
> fasta.file <- system.file("stx.fa", package = "openPrimeR")
> ```
> where stx.fa il the file I wanted to open and that is present in the
> working directly. I get only an empty object.
> What am I getting wrong?
> Thank you
>
>
> --
> Best regards,
> Luigi
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] .Rprofile with devtools::install_github() loops

2021-02-10 Thread Bill Dunlap
Installing a package involves running several R subprocesses, each of
which is running that .Rprofile.  You may be able to stop the infinite
recursion by setting an environment variable that subprocesses can
check.  E.g. replace
  install_github("xxx/yyy")
with
  if (Sys.getenv("INSTALLING_FROM_GITHUB", unset="no") == "no") {
Sys.setenv(INSTALLING_FROM_GITHUB="yes")
install_github("xxx/yyy")
  }

[This is totally untested.]

-Bill

On Wed, Feb 10, 2021 at 12:45 AM Chris Evans  wrote:
>
> I am sure this must be documented somewhere and that I'm missing something 
> obvious but some searching isn't finding an answer and I'm sure there is one.
>
> I have created a very simple package on GitHub and want my machines (other 
> than the one that built it) to load it when they start R using 
> devtools::install_github()
>
> The install_github() call works fine from the console but when I put it in my 
> .Rprofile it just loops on restarting R.  I _think_ it may be that 
> devtools::install_github()
> is restarting the session as I found one thing on the web suggesting that may 
> be the case.  However, I think if it were the case it would be documented and 
> I'd find
> far more about that.
>
> OK.  So my .Rprofile is:
>
> print("This is a message from /home/chris/.Renviron: hello Chris!")
> .First <- function(){
> devtools::install_github("/")
> }
> print("OK, off you go!")
>
> I have obscured my package to protect my blushes but I get the same behaviour 
> with r-lib/devtools and, as I say, my little package loads OK from the 
> console.
>
> You can see I tried wrapping it in a .First() function but that didn't change 
> anything.
>
> True both on a Linux machine and a Windows machine.
>
> OK.  Anyone save me from more dents in the wall and frontal lobe damage?!
>
> TIA,
>
> Chris
>
> --
> Small contribution in our coronavirus rigours:
> https://www.coresystemtrust.org.uk/home/free-options-to-replace-paper-core-forms-during-the-coronavirus-pandemic/
>
> Chris Evans  Visiting Professor, University of Sheffield 
> 
> I do some consultation work for the University of Roehampton 
>  and other places
> but  remains my main Email address.  I have a work web site 
> at:
>https://www.psyctc.org/psyctc/
> and a site I manage for CORE and CORE system trust at:
>http://www.coresystemtrust.org.uk/
> I have "semigrated" to France, see:
>https://www.psyctc.org/pelerinage2016/semigrating-to-france/
>
> https://www.psyctc.org/pelerinage2016/register-to-get-updates-from-pelerinage2016/
>
> If you want an Emeeting, I am trying to keep them to Thursdays and my diary 
> is at:
>https://www.psyctc.org/pelerinage2016/ceworkdiary/
> Beware: French time, generally an hour ahead of 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.


Re: [R] Working with FactoMineR

2021-02-04 Thread Bill Dunlap
This will happen if you select no points when it asks you to 'click on
the graph' (to select the level at which to cut the tree).  On Windows
you can select no points by right clicking and selecting 'Stop' from
the menu that pops up.  RStudio may have a different way to select no
points.

-Bill

On Thu, Feb 4, 2021 at 9:04 AM Mahmood Naderan-Tahan
 wrote:
>
> Hi,
>
> I tried to run the HCPC example [1] in the online R [2], but got an error:
>
>
>
> library(FactoMineR)
> data(tea)
> res.mca = MCA(tea, ncp=20, quanti.sup=19, quali.sup=c(20:36), graph=FALSE)
> res.hcpc = HCPC(res.mca)
>
>
>
> Result:
>
> [1] "Click on the graph to cut the tree"
> Error in while (coupe$y < min(t$tree$height)) { :
>   argument is of length zero
> Calls: HCPC
> Execution halted
>
>
> [1] "Click on the graph to cut the tree"
>
> Error in while (coupe$y < min(t$tree$height)) { :
>
> argument is of length zero
>
> Calls: HCPC
>
> Execution halted
>
>
>
> May I know how to fix that?
>
>
>
> [1] 
> http://factominer.free.fr/factomethods/hierarchical-clustering-on-principal-components.html
>
> [2] https://rdrr.io/snippets/
>
>
> Regards,
> Mahmood
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 when calling (R 4.0.x on Windows) from Python

2021-02-02 Thread Bill Dunlap
R/Rterm now has shell-independent ways to specify its standard input
file, --file=file.R, and environment variables, VAR=VALUE.  Should it
also have shell-independent arguments to specify files to contain
stdout and stderr or both?  Then its help message could omit the '>
output' (it can already leave out the '< infile').

The help message could then say that if those arguments are omitted
then Rterm uses stdin, stdout, and stderr.  Thus the user could come
up with the shell syntax if the user needed to use pipes or output
stream merging, etc.

-Bill

On Tue, Feb 2, 2021 at 5:49 AM Tomas Kalibera  wrote:
>
> A reproducible example:
>
> system("\"C:\\Program Files\\R\\R-4.0.3\\bin\\R.exe\" -e commandArgs()
>  >out")  # does not create "out"
> system("\"C:\\Program Files\\R\\R-3.6.3\\bin\\R.exe\" -e commandArgs()
>  >out")  # creates "out"
>
> Note that this does not create "out", either:
>
> system("\"C:\\Program Files\\R\\R-3.6.3\\bin\\x64\\Rterm.exe\" -e
> commandArgs() >out")
>
> I think redirections should be left to the shell, so e.g. those calls
> from Python should use "os.system" if they needed redirection, as Duncan
> suggested.
>
> I see that both R.exe and Rterm.exe give "Usage: Rterm [options] [<
> infile] [> outfile] [EnvVars]", which may be confusing to programmers
> invoking R without a shell, but then talking there about invocation via
> shell could confuse typical users, instead.
>
> My best guess is that the redirection in R.exe in 3.6 worked rather by
> accident, as a consequence of that R.exe internally invoked (and still
> invokes) Rterm.exe via the shell, but R.exe did not protect all
> arguments from expansions from that internal shell invocation. If
> redirection was meant to work without external shell, it would have
> instead been implemented explicitly also in Rterm.exe.
>
> My change 77926 made sure that all arguments to that internal shell
> invocation were protected, following bug reports such as PR#17709, where
> users had "&" in their file names. Therefore, this works, executing file
> code&.r
>
> system("\"C:\\Program Files\\R\\R-4.0.3\\bin\\R.exe\" -f code&.r")
>
> but not with 3.6.3, and I would not be surprised if even more special
> characters became popular, soon.
>
> After all, what if someone wanted to pass an argument to R including
> ">", that should work, too:
>
>  t.r 
> cat("Header: ", commandArgs(TRUE)[1], "\n")
> -
>
> system("\"C:\\Program Files\\R\\R-4.0.3\\bin\\R.exe\" -f t.r --args
> ") # prints Header:  
> system("\"C:\\Program Files\\R\\R-3.6.3\\bin\\R.exe\" -f t.r --args
> ") # fails with  The syntax of the command is incorrect.
>
> So in summary, I don't agree this is a bug.
>
> Best
> Tomas
>
> On 1/29/21 11:19 AM, Duncan Murdoch wrote:
> > On 29/01/2021 3:57 a.m., Marcel Baumgartner wrote:
> >> Dear Bill, Duncan and Martin,
> >>
> >> thanks for your investigation. Can you clarify on next steps? Is this
> >> now an official bug, or have you found a workaround? For your
> >> information: the issue showed up the first time when I called R 4.0.2
> >> from within a software called "IDEA" (from Caseware Analytics), using
> >> their scripting language (similar to Visual Basic). With my colleague
> >> we then simply reproduce the error calling R from Python, so that we
> >> could share it more easily. When we run this command directly on the
> >> CMD in Windows, all works fine. The issue only happens when R is
> >> called within another software.
> >>
> >
> > I would say this is a bug, with two workarounds.  These are only
> > needed (and will only work) on Windows.
> >
> > 1.  If you want to include redirection in the command line, then call
> > cmd.exe yourself, and have it call Rterm.exe.  I think your original
> > command
> >
> > R.exe -f code.R --args "~/file.txt" 1> "~/log.txt" 2>&1"
> >
> > could be written as
> >
> > cmd.exe 1>log.txt 2>&1 /C R.exe -f code.R --args "~/file.txt"
> >
> > (but I haven't tested it).  You could also use the slightly more
> > efficient
> >
> > cmd.exe 1>log.txt 2>&1 /C Rterm.exe -f code.R --args "~/file.txt"
> >
> > if Rterm.exe is on your path; by default I don't think it will be.
> >

  1   2   3   4   >