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

2020-08-31 Thread William Dunlap via R-help
Which version of java do you have installed? Oracle's web site says ojdbc5.jar is for Java 1.5 and ojdbc6.jar is for more recent versions. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Aug 31, 2020 at 3:56 AM Christofer Bogaso wrote: > > Hi, > > I am trying to establish a connection to

Re: [R] serialize does not work as expected

2020-08-29 Thread William Dunlap via R-help
For some reason l[[2]] is serialized as a 'compact_realseq' and l[3]] is not. They both unserialize to the same thing. On Windows I get: > lapply(l, function(x)rawToChar(serialize(x, connection=NULL, ascii=TRUE))) [[1]] [1]

Re: [R] Passing formula and weights error

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

Re: [R] [External] rNOMADS package

2020-08-24 Thread William Dunlap via R-help
Add the arguments type="source" and repos=NULL to your call to install.packages(). repos=NULL means that this is a local file, not something to download from a repository. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Aug 24, 2020 at 8:31 AM Richard M. Heiberger wrote: > > incorrect

Re: [R] & and |

2020-08-19 Thread William Dunlap via R-help
Instead of intersect you could use grepl(pattern1,x) & grepl(pattern2,x). Use which() on the result if you must have integers, but the logicals that grepl() produces are often easier to use as subscripts. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Aug 19, 2020 at 8:54 AM Ivan Calandra

Re: [R] Dependent Variable in Logistic Regression

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

Re: [R] Looping thorugh dataframe

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

Re: [R] How to convert column from millisecond epoch time to yyyy-mm-dd GMT

2020-06-23 Thread William Dunlap via R-help
When you give an example it really helps to (a) show the data as the output of dput() or dump() so one can copy and paste into R and (b) show the result (the wrong value or error message) that you got. You example is missing some quotes and has an unneeded call to lapply(). > dump("Data",

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

2020-06-19 Thread William Dunlap via R-help
It is a bug that has been present in R since at least R-2.14.0 (the oldest that I have installed on my laptop). Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Jun 19, 2020 at 10:37 AM Rui Barradas wrote: > Hello, > > > Thanks, I hadn't thought of that. > > But, why? Is it evaluated once

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

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

Re: [R] Error in gee.fit$working.correlation[1, 2] : subscript out of bounds

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

Re: [R] na.omit not omitting rows

2020-06-04 Thread William Dunlap via R-help
Does droplevels() help? > d <- data.frame(size = factor(c("S","M","M","L","L"), levels=c("S","M","L")), id=c(101,NA,NA,104,105)) > str(d) 'data.frame': 5 obs. of 2 variables: $ size: Factor w/ 3 levels "S","M","L": 1 2 2 3 3 $ id : num 101 NA NA 104 105 > str(na.omit(d)) 'data.frame': 3

Re: [R] Partial matching list elements in R 4.0

2020-05-27 Thread William Dunlap via R-help
all.equal() Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, May 27, 2020 at 1:13 PM John Harrold wrote: > Thankyou Bert and Bill. > > I have one last question. Is there a tool that will recursively compare > two lists to find differences in both their structure and contents? > > I'm

Re: [R] Partial matching list elements in R 4.0

2020-05-26 Thread William Dunlap via R-help
Another symptom of this problem is: > {x <- list(Abc=list(Pqr="Old Abc$Pqr")); x$Ab$Pqr <- "New Ab$Pqr" ; x} R version 3.6.2 (2019-12-12) | R version 4.0.0 (2020-04-24) List of 2| List of 2 $ Abc:List of 1 | $ Abc:List of 1 ..$ Pqr: chr "Old Abc$Pqr" | ..$

Re: [R] NA command in a 'for' loop

2020-04-21 Thread William Dunlap via R-help
Read the files with read.csv(filename) or read.table(sep=",", filename) so the commas don't become part of the R data.frame. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Apr 21, 2020 at 10:17 AM Helen Sawaya wrote: > Thank you for your patience. > > This is the output of dput(head(d,

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

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

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

2020-04-08 Thread William Dunlap via R-help
>I would like to create a new column called PHENO which would satisfy >these >conditions: > >if CURRELIG=1 and RTNPTHY=1 than PHENO=1 >if PLASER=2 than PHENO=2 >otherwise is -9 I assume that if CURRELIG==1 and RNPTHY==1 and PLASER==2 then PHENO should be 1. Or should that case flag a data

Re: [R] nls problem

2020-04-03 Thread William Dunlap via R-help
If you will be copying the printed coefficients into your function (instead of just using fitted() or predict()), then use dput(coef(m)) to get them printed to full precision. Also, if you regress on pH-7 instead of pH you don't have to worry so much about the roundoff or cancellation error.

Re: [R] nls problem

2020-04-02 Thread William Dunlap via R-help
Roundoff/cancelation error: compare the following. The first is equivalent to your function, the last to fitted(). > with(aedf, t(cbind(1, pH, pH^2) %*% round(coef(m), digits=2))) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]

Re: [R] cannot coerce class '"expression"' to a data.frame

2020-03-21 Thread William Dunlap via R-help
Try using the I() function in the call to data.frame. E.g., > d <- data.frame(X=1:3, Y=1:3, Substance=I(expression(H[2]*O, H[2] * O[2], H*S*O[4]))) > with(d, {plot(X,Y,type="n",xlim=c(0,4)); text(X, Y, Substance)}) Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Mar 21, 2020 at 1:45 AM

Re: [R] fit for truncated normal distribution

2020-03-14 Thread William Dunlap via R-help
On Linux it says "Program received signal SIGFPE, Arithmetic exception". I think the only way to get a SIGFPE (floating point exception) any more (on machines with IEEE floating point arithmetic) is taking an integer modulo zero, which do_druncnorm does when length(x) is 0: const double cx

Re: [R] file.access returning -1 for a file on remote Windows drive.

2020-02-28 Thread William Dunlap via R-help
If file.access() says the file is unreadable but file() says it can be opened, why don't you just open the file and read it? You can use tryCatch to deal with problems opening or reading the file. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Feb 28, 2020 at 2:54 PM Sam Albers wrote:

Re: [R] How to index the occasions in a vector repeatedly under condition 1? if not, it will give a new index.

2020-02-21 Thread William Dunlap via R-help
> all.equal(y, ave(d, cumsum(c(TRUE,is_true(diff(a)!=0))), FUN=function(di)1L+cumsum(is_true(di>15 [1] TRUE Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Feb 19, 2020 at 7:20 PM Lijun Zhao wrote: > Dear William, > > Thank you so much. > > > > I am quiet new in R. I would like to do

Re: [R] How to index the occasions in a vector repeatedly under condition 1? if not, it will give a new index.

2020-02-19 Thread William Dunlap via R-help
Use cumsum(logicalVector) to increment a counter at the TRUE positions in logicalVector. . E.g., > d <- c(NA, 0, 0, 0, 8, 0, 577, 69, 0) > is_true <- function(x) !is.na(x) & x > 1 + cumsum( is_true(d >= 15) ) [1] 1 1 1 1 1 1 2 3 3 Some packages have the equivalent of that is_true function,

Re: [R] Aggregate individual level data to age categories

2020-02-12 Thread William Dunlap via R-help
You didn't say how you wanted to use it as a data.frame, but here is one way d <- data.frame( check.names = FALSE, age = c(45L, 45L, 46L, 47L, 47L), x = c(1L, 2L, 1L, 3L, 3L)) with(d, as.data.frame(table(age,x))) which gives: age x Freq 1 45 11 2 46 11 3 47 10 4 45

Re: [R] N Sizes between Pairs of Columns using cor(, , , use = 'pairwise')

2020-01-21 Thread William Dunlap via R-help
crossprod(!is.na(tmp)) Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Jan 21, 2020 at 11:56 AM Doran, Harold wrote: > I'm trying to find an efficient way to find the N size on correlations > produced when using the pairwise option in cor(). > > Here is a sample to illustrate: > > ###

Re: [R] How does one pass arguments to a function, such as coxph, that itself is inside a function?

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

Re: [R] table and unique seems to behave differently

2019-12-10 Thread William Dunlap via R-help
You can use save(ascii=TRUE,...) to make an ascii-only RData file that you can include in the mail message. E.g., > x <- c(3.4, 3.4 + 1e-15) > save(x, ascii=TRUE, file=stdout()) RDA3 A 3 198145 197888 5 UTF-8 1026 1 262153 1 x 14 2 3.4 3.401 254 Bill Dunlap TIBCO Software wdunlap

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

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

Re: [R] Can file size affect how na.strings operates in a read.table call?

2019-11-14 Thread William Dunlap via R-help
read.table (and friends) also have the strip.white argument: > s <- "A,B,C\n0,0,0\n1,-99,-99\n2,-99 ,-99\n3, -99, -99\n" > read.csv(text=s, header=TRUE, na.strings="-99", strip.white=TRUE) A B C 1 0 0 0 2 1 NA NA 3 2 NA NA 4 3 NA NA > read.csv(text=s, header=TRUE, na.strings="-99",

Re: [R] using xpath with xml2

2019-11-12 Thread William Dunlap via R-help
> xml_ns(daymet) d1<-> http://www.unidata.ucar.edu/namespaces/thredds/InvCatalog/v1.0 xlink <-> http://www.w3.org/1999/xlink > daymet %>% xml2::xml_find_all(xpath = "d1:dataset") {xml_nodeset (1)} [1] https://thredds.daac.ornl.gov/thredds/catalog/ornldaac/1328/catalog.xml; > > # run the

Re: [R] problem in WRS2

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

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

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

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

2019-10-30 Thread William Dunlap via R-help
Using NROW(x) instead of length(x) is fine, but it won't fix the problem that this function won't work if given a tibble. E.g., for a tibble t, rev(t) is identical to t. revx <- ts(rev(x),frequency=12) revx <- revx[1:(NRngt$(revx)-dt2)] fc <- forecast(auto.arima(revx),bfct) Bill

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

2019-10-30 Thread William Dunlap via R-help
Your EXTEND() function appears to expect that its 'x' argument will be a numeric vector, but you pass it a one-column tibble. Hence length(x) is 1 and things go downhill from there. I like to start such functions with a long stopifnot() statement that does a quick check of inputs. E.g.,

Re: [R] Error when using qvalue function

2019-10-28 Thread William Dunlap via R-help
With qvalue-2.16.0 and R-3.6.1 many calls to qvalue::qvalue die in its call to qvalue::pi0est. E.g., > trace(smooth.spline, quote(cat("y=", deparse(y), "\n"))) Tracing function "smooth.spline" in package "stats" [1] "smooth.spline" > qvalue::pi0est(c(.01, .01, .06)) Tracing smooth.spline(lambda,

Re: [R] "chi-square" | "chi-squared" | "chi squared" | "chi, square"

2019-10-19 Thread William Dunlap via R-help
Sigma squared or sigma square? Hotelling's T-squared or T-square? Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Oct 19, 2019 at 7:38 AM Therneau, Terry M., Ph.D. via R-help < r-help@r-project.org> wrote: > Martin, >A fun question. > > Looking back at my oldest books, Feller (1950)

Re: [R] Surprising Symbolic Model Formula Evaluations

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

Re: [R] Choosing specific Date Range from non-sequential Date

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

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

2019-08-29 Thread William Dunlap via R-help
Element #2 of that output, the empty fomula " F1=~ ", triggers the bug in omegaSem. omegaSem needs to ignore such entries in omega's output. psych's author should be able to fix things up. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Aug 29, 2019 at 12:31 PM Danilo Esteban Rodriguez

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

2019-08-29 Thread William Dunlap via R-help
Please use 'reply to all' for responses to R-help reponses. What do you get with your original data for psych::omega(my.data)$model$lavaan ? Any entries like "F3=~"? Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Aug 29, 2019 at 12:05 PM Danilo Esteban Rodriguez Zapata <

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

2019-08-29 Thread William Dunlap via R-help
> omegaSem(r9,n.obs=198) Error in parse(text = x, keep.source = FALSE) : :2:0: unexpected end of input This error probably comes from calling factor("~") and psych::omegaSem(data) will do that if all the columns in data are very highly correlated with one another. In that case

Re: [R] Creating data using multiple for loops

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

Re: [R] gmp coredump - where to report?

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

Re: [R] separate and gather functions

2019-08-12 Thread William Dunlap via R-help
This one uses only core R functions. Does that count toward "elegance"? > # your data, I assume, in a form one can copy and paste into R > d <- data.frame(stringsAsFactors = FALSE, Col1 = c("Agency A", "Agency B", "Agency C"), Col2 = c("Function1, Function2, Function3, Function4",

Re: [R] Loading large tar.gz XenaHub Data into R

2019-08-01 Thread William Dunlap via R-help
By the way, instead of saying only that there were warnings, it would be nice to show some of them. E.g., > z <- readLines(" https://tcga.xenahubs.net/download/TCGA.GBMLGG.sampleMap/HumanMethylation450.gz ") [ Hit control-C or Esc to interrupt, or wait a long time ] There were 50 or more warnings

Re: [R] Printing vector

2019-07-22 Thread William Dunlap via R-help
By the way, the default print method has the argument 'na.print' that can speciify how to print an NA value. E.g., > print(c(1234/, NA, 1), na.print="n/a") [1] 0.1234123 n/a 1.000 > print(c(1234/, NA, 1), na.print="") [1] 0.1234123 1.000 > print(c(1234/, NA,

Re: [R] Printing vector

2019-07-22 Thread William Dunlap via R-help
The following mimics Fortran printing with format F.. print1 <- function (x, perLine = 10, fWidth = 8, fPrecision = 2, fortranStars = TRUE) { format <- paste0("%", fWidth, ".", fPrecision, "f") oldWidth <- getOption("width") on.exit(options(width = oldWidth)) options(width =

Re: [R] R 3.6.1 and apcluster package

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

Re: [R] R 3.6.1 and apcluster package

2019-07-18 Thread William Dunlap via R-help
Note that you can reproduce this in R-3.5.1 if you specify serialization version 3 (which became the default in 3.6.0). > save(apresX, file="351-2.RData", version=2) > save(apresX, file="351-2.RData", version=3) Error: C stack usage 7969184 is too close to the limit > version$version.string [1]

Re: [R] Read Unicode text (*.txt)

2019-07-02 Thread William Dunlap via R-help
Try changing encoding="UTF-16" to fileEncoding="UTF-16". Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Jul 1, 2019 at 9:30 PM javad bayat wrote: > Dear all; > I use your suggestion but I gave the same warning messages. I changed the > file name (Data.csv). > " >

Re: [R] Read Unicode text (*.txt)

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

Re: [R] Read Unicode text (*.txt)

2019-07-01 Thread William Dunlap via R-help
Should that encoding="UTF-8" be encoding="UTF-16"? Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Jul 1, 2019 at 2:45 PM Jim Lemon wrote: > Hi Javad, > Unicode characters do have embedded nulls. Try this: > > d4<-read.table("./4.csv",sep=";",header=TRUE,encoding="UTF-8") > > Jim > >

Re: [R] problem in saving the history file '~/.Rhistory'

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

Re: [R] Problem with reading file saved in directory

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

Re: [R] Recovering former projects on R

2019-06-21 Thread William Dunlap via R-help
You should ask someone at RStudio about this, but *.Rproj files are not something R itself knows about. load() reads files made by save(), which usually have the extension ".Rdata" or ".rda". Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Jun 21, 2019 at 1:43 PM Spencer Brackett <

Re: [R] Help with another ggplot error

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

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

2019-06-12 Thread William Dunlap via R-help
strcapture() can help here. > mystrings<-c("ABC","A(B)C","AB(C)") > strcapture("^[^{]*(\\([^(]*\\)).*$", mystrings, proto=data.frame(InParen="")) InParen 1 2 (B) 3 (C) Classic regular expressions don't do so well with nested parentheses. Perhaps a perl-style RE could do that. >

Re: [R] [Rd] Open a file which name contains a tilde

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

Re: [R] Calculating date difference in days

2019-05-22 Thread William Dunlap via R-help
You can use units<- to change the time units of the difference. E.g., > d <- as.POSIXlt("2018-03-10") - as.POSIXlt("2018-03-09 02:00:00") > d Time difference of 22 hours > units(d) <- "days" > d Time difference of 0.917 days > > units(d) <- "mins" > d Time difference of 1320 mins > units(d)

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

2019-05-17 Thread William Dunlap via R-help
-[[:digit:]]{2}-[[:digit:]]{2} > + [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}) +(<[^>]*>) *(.*$)", > + a, proto=data.frame(stringsAsFactors=FALSE, When="", > Who="", > + What="")) > > But al

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

2019-05-17 Thread William Dunlap via R-help
Consider using readLines() and strcapture() for reading such a file. E.g., suppose readLines(files) produced a character vector like x <- c("2016-10-21 10:35:36 What's your login", "2016-10-21 10:56:29 John_Doe", "2016-10-21 10:56:37 Admit#8242", "October 23,

Re: [R] Question about addressing a data frame

2019-04-25 Thread William Dunlap via R-help
is.na(DF) is a matrix for a data.frame DF. The semantics of '[" are different for matrices and data.frame and that can cause confusion > DF <- data.frame(X=c(101,NA,NA), Y=c("one","two",NA), row.names=c("i","ii","iii")) > is.na(DF) # returns a matrix when given a data.frame X Y i

Re: [R] Problems w/ creating object

2019-04-22 Thread William Dunlap via R-help
Also, recall that on Windows each drive has its own root directory so the meaning of "/some/file" depends on where your working directory is at the moment. E.g., > setwd("C:/tmp") > cat(file="junk.txt",1:10) > file.info("/tmp/junk.txt") size isdir mode mtime

Re: [R] Problems w/ creating object

2019-04-22 Thread William Dunlap via R-help
file.info( "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt" ) would tell about the permissions on the file, if it exists (and give NA's if it did not). Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Apr 22, 2019 at 2:00 PM David Winsemius wrote: > > On 4/22/19 11:49 AM,

Re: [R] problem(s) compiling RWinEdt

2019-04-22 Thread William Dunlap via R-help
Trying adding INSTALL_opts="--no-test-load" to your install.packages(type="source",...) command. This package is being too clever in its .onAttach function. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Apr 22, 2019 at 9:07 AM Evan Cooch wrote: > [Note: if this should go to one of

Re: [R] Debugging Rmarkdown

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

Re: [R] lm fails on some large input

2019-04-18 Thread William Dunlap via R-help
This sort of data arises quite easily if you deal with time/dates around now. E.g., > d <- data.frame( + when = seq(as.POSIXct("2017-09-29 18:22:01"), by="secs", len=10), + measurement = log2(1:10)) > coef(lm(data=d, measurement ~ when)) (Intercept) when

Re: [R] Why is it not possible to cut a tree returned by Agnes or Diana by height?

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

Re: [R] Are fitted.values available in pglm?

2019-04-12 Thread William Dunlap via R-help
You should ask the maintainer of the package about this: bug.report(package="pglm") or maintainer("pglm") should give you contact information. The help file for pglm seems all wrong - it says pglm's output has class "pglm" with components like "fitted.values", but the the example calls to pglm

Re: [R] Fwd: high p values

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

Re: [R] How to list recursive package dependency prior to installation/upgrade of a package

2019-03-14 Thread William Dunlap via R-help
available.packages() and installed.packages() map package names to version and a lot of other things. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Mar 14, 2019 at 1:03 PM Sebastien Bihorel < sebastien.biho...@cognigencorp.com> wrote: > That is great! > > Is there a way to know version

Re: [R] How to list recursive package dependency prior to installation/upgrade of a package

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

Re: [R] Sorting vector based on pairs of comparisons

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

Re: [R] inverse of which()

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

Re: [R] Which dependency list to build first?

2019-02-27 Thread William Dunlap via R-help
Did you use 'R CMD ldd .../later.so', as I recommended? Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Feb 27, 2019 at 12:51 PM Rich Shepard wrote: > On Wed, 27 Feb 2019, William Dunlap wrote: > > > The package will not load. The only reason to do test load is to examine > > why the

Re: [R] Which dependency list to build first?

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

Re: [R] Which dependency list to build first?

2019-02-27 Thread William Dunlap via R-help
Using the syntax 'install.packages("later") --no-test-load' The syntax is either install.packages("later", type="source", INSTALL_opts="--no-test-load") from within R (perhaps with repos=NULL if from a local directory) or R CMD INSTALL --no-test-load later from outside of R, where

Re: [R] Which dependency list to build first?

2019-02-27 Thread William Dunlap via R-help
Add the --no-test-load option to the install command and the unloadable .so file should be left there so you can look at its dependencies with, e.g., 'R CMD ldd .../libs/later.so'. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Feb 27, 2019 at 9:40 AM Rich Shepard wrote: > On Wed, 27

Re: [R] Second attempt: Cannot reproduce tutorial results

2019-02-25 Thread William Dunlap via R-help
Do you see anything wrong with this line? titles <- c(title, extractTitle(data.combined[i, "name"])) } Hint - plural or singular? Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Feb 25, 2019 at 11:38 AM Jason Hernandez via R-help < r-help@r-project.org> wrote: > Okay, I switched to

Re: [R] Ghost variables

2019-02-25 Thread William Dunlap via R-help
Doesn't that mean that your script is incomplete, that it needs to make those variables? Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Feb 25, 2019 at 10:32 AM wrote: > Fellow R-gonauts: > > I frequently erase/remove all the objects in my current environment so can > I re-run scripts

Re: [R] Save creates huge files, dump doesn't

2019-02-20 Thread William Dunlap via R-help
Also, note that the function function(x) x has no free variables so it doesn't matter what environment encloses it. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Feb 20, 2019 at 7:47 AM William Dunlap wrote: > object@transforms@transforms$PC1.all@f > function(x) x > > Do you

Re: [R] Save creates huge files, dump doesn't

2019-02-20 Thread William Dunlap via R-help
object@transforms@transforms$PC1.all@f function(x) x Do you know how to 'see' what's in 0x3314db8 ? ls.str(all=TRUE, environment(object@transforms@transforms$PC1.all@f) will list the names, types, summaries, etc. of the objects in that environment. Bill Dunlap TIBCO Software wdunlap tibco.com

Re: [R] Save creates huge files, dump doesn't

2019-02-19 Thread William Dunlap via R-help
One reason save() makes bigger files than dump() is that save() saves environments associated with functions that are saved and those environments may contain large datasets that are not really needed. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Feb 19, 2019 at 11:59 AM Jeff Newmiller

Re: [R] POSIXlt class and lapply

2019-02-14 Thread William Dunlap via R-help
Somewhere between R-3.3.3 and R-3.5.2 a POSIXlt method for as.list() was added, and lapply probably calls as.list(). > RCompare(methods("as.list")) R version 3.3.3 (2017-03-06)| R version 3.5.1 (2018-07-02) [1] as.list.data.frame as.list.Date| [1]

Re: [R] Difficulty with "\\" in string functions....

2019-02-11 Thread William Dunlap via R-help
You can also avoid the issue by using the basename and dirname functions. > Fname1 <- "D:\\Data\\OneDrive\\ISTA Documents\\QT_App\\QT Analysis Input Data Example WorkBook.xlsx" > basename(Fname1) [1] "QT Analysis Input Data Example WorkBook.xlsx" > dirname(Fname1) [1] "D:/Data/OneDrive/ISTA

Re: [R] data.frame() versus as.data.frame() applied to a matrix.

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

Re: [R] Why is there error in as.POSIXlt.character when using strftime()?

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

Re: [R] periodicity

2019-01-30 Thread William Dunlap via R-help
Searching for 'periodicity' on rseek.org gives, several items from the top, *periodicity* function | *R* Documentation https://www.rdocumentation.org/packages/xts/.../0.11.../*periodicity* Estimate the *periodicity*

Re: [R] periodicity

2019-01-30 Thread William Dunlap via R-help
Search with https://rseek.org Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Jan 30, 2019 at 11:17 AM Nick Wray via R-help wrote: > I've found references on websites to an R function "periodicity", but > there's no such built-in function as far as I can see in R studio. I can't > find

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

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

Re: [R] TIme Zone error

2019-01-26 Thread William Dunlap via R-help
> Sys.setenv(TZ="US/Eastern") > as.POSIXlt("2019-01-26 01:19") [1] "2019-01-26 01:19:00 EST" > Sys.setenv(TZ="Asia/Calcutta") > as.POSIXlt("2019-01-26 01:19") [1] "2019-01-26 01:19:00 IST" (Sys.getenv("Asia/Calcutta") returns the value of the environment variable "Asia/Calcutta". It does not set

Re: [R] Diff'ing 2 strings

2019-01-10 Thread William Dunlap via R-help
> args(tools::Rdiff) function (from, to, useDiff = FALSE, forEx = FALSE, nullPointers = TRUE, Log = FALSE) NULL > version$version.string [1] "R version 3.4.3 (2017-11-30)" (The 'tools' package is not attached by default, so use ::.) Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Jan

Re: [R] g++ error causes non-zero exit status for package installation

2019-01-05 Thread William Dunlap via R-help
You would get these errors ("R: file or directory not found, version: file or directory not found...") if you had a ~/.Rprofile file containing the line 'cat(version$version.string, sep="\n"). Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Jan 5, 2019 at 1:23 AM Winfried Moser wrote: >

Re: [R] Error in names(x) <- value: 'names' attribute must be the same length as the vector in gam function

2019-01-04 Thread William Dunlap via R-help
mgcv::s() does not appear to work with objects of class "Date". E.g., > d <- data.frame(date=seq(as.Date("2018-12-20"),len=10,by="week"), response=log2(1:10)%%1) > model <- gam(data=d, response ~ s(date)) Error in names(dat) <- object$term : 'names' attribute [1] must be the same length as the

Re: [R] Problem with system() and source on linux

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

Re: [R] convert columns of dataframe to same factor levels

2018-12-19 Thread William Dunlap via R-help
You can abuse the S4 class system to do this. setClass("Size") # no representation, no prototype setAs(from="character", to="Size", # nothing but a coercion method function(from){ ret <- factor(from, levels=c("Small","Medium","Large"), ordered=TRUE) class(ret) <- c("Size", class(ret))

Re: [R] Drawing a random number

2018-11-29 Thread William Dunlap via R-help
sample( setdiff(10:1000, Vec), size=1) Also, note that as.integer(runif(1, min, max)) will almost never return max. Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Nov 29, 2018 at 11:14 AM Christofer Bogaso < bogaso.christo...@gmail.com> wrote: > Hi, > > I would like to draw an Integer

Re: [R] extrat non diagonal

2018-11-14 Thread William Dunlap via R-help
Another way: > A <- matrix(1:9,3,3, dimnames=list(Row=paste0("r",1:3),Col=paste0("c",1:3))) > A Col Row c1 c2 c3 r1 1 4 7 r2 2 5 8 r3 3 6 9 > matrix( A[row(A)!=col(A)], nrow(A)-1, ncol(A), dimnames=list(NULL, colnames(A))) c1 c2 c3 [1,] 2 4 7 [2,] 3 6 8 Bill

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

2018-11-13 Thread William Dunlap via R-help
Perhaps you got bitten by Dolphin's non-modal dialogs, as described in https://userbase.kde.org/Dolphin/File_Management: Non Modal Dialogs When Moving, Copying or Deleting files/directories the dialog disappears even when the operation has not yet completed. A progress bar then appears in the

  1   2   3   4   5   >