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

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:

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

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

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

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" ";

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

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

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",

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 $

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

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

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.

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

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 <- "(.*<[^>]+

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

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

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

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,

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

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

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)

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

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

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

Re: [R] Error with text analysis data

2022-04-13 Thread Bill Dunlap
uggest 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 >

Re: [R] Error with text analysis data

2022-04-13 Thread Bill Dunlap
ike 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 > &

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

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

Re: [R] [External] Funky calculations

2022-02-02 Thread Bill Dunlap
: %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 >

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

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

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

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 >

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

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 emai

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

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

2021-12-20 Thread Bill Dunlap
" [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: >

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, "$",

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

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

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

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,

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

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.

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

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

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

Re: [R] I'd like to request that my R CRAN package is not tested on Solaris OS

2021-10-22 Thread Bill Dunlap
e >> 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 se

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

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.

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

2021-09-30 Thread Bill Dunlap
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 >

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

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

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

Re: [R] 'Double to logical' error

2021-09-07 Thread Bill Dunlap
`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. > > > > > ---

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

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,

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, ...)

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

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

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

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]

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

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

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"

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

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

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

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

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

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

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

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

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

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

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.

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

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 =

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

2021-03-29 Thread Bill Dunlap
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...@gmai

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

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

2021-03-29 Thread Bill Dunlap
ette 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 > Ogg

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) ==

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]

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

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

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

Re: [R] Warning messages while parallel computing

2021-03-04 Thread Bill Dunlap
1 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,

Re: [R] Warning messages while parallel computing

2021-03-04 Thread Bill Dunlap
k 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, >

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

Re: [R] Read

2021-02-22 Thread Bill Dunlap
1 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="

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

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

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

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

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-02-02 Thread Bill Dunlap
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 "~/

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Bill Dunlap
"[3] \"--vanilla\" " [5] "[4] \"-e\" " "[5] \"commandArgs()\" " [7] "[6] \"SPACE/log.txt\" " "> " [9] "> " > > unlink(logname) > system(p

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Bill Dunlap
I believe the problem is from svn 77925 in gnuwin/front-ends/rcmdfn.c, which was committed a few days after 3.6.3 was released. Rterm used to put double quotes around a command line argument only if it contained a space, now it double quotes all arguments. It sees shell constructs like "1>" and

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Bill Dunlap
t; print(cmd403) C:/R/R-4.0.3/bin/R.exe --vanilla --quiet -e "commandArgs()" --args "arguments.txt" 1> "log403.txt" 2>&1 >>> status403 = subprocess.call(cmd403) > commandArgs() [1] "C:\\R\\R-4.0.3/bin/x64/Rterm.exe" "--vanilla" [3

Re: [R] Error when calling (R 4.0.x on Windows) from Python

2021-01-27 Thread Bill Dunlap
Note that in R-3.6.3 commandArgs() does not include the arguments intended to be processed by the shell, "1>", "arguments.txt", etc., but in R-4.0.3 it does include them. It is as though an R shell() command was replaced by a system() command so cmd.exe didn't get a chance to process the command

  1   2   >