Re: [R] [External] Re: Building Packages. (fwd)

2024-03-21 Thread luke-tierney--- via R-help

[forgot to copy to R-help so re-sending]

-- Forwarded message --
Date: Thu, 21 Mar 2024 11:41:52 +
From: luke-tier...@uiowa.edu
To: Duncan Murdoch 
Subject: Re: [External] Re: [R] Building Packages.

At least on my installed version (which tells me it is out of date)
they appear to just be modifying the "package:utils" parent frame of
the global search path.

There seem to be a few others:

checkUtilsFun <- function(n)
identical(get(n, "package:utils"), get(n, getNamespace("utils")))
names(which(! sapply(ls("package:utils", all = TRUE), checkUtilsFun)))
## [1] "bug.report"   "file.edit""help.request" ## [4] "history" 
"install.packages" "remove.packages" ## [7] "View"


I don't know why they don't put these overrides in the tools:rstudio frame.
At least that would make them more visible.

You can fix all of these with something like

local({
  up <- match("package:utils", search())
  detach("package:utils")
  library(utils, pos = up)
})

or just install.packages with

local({
up <- match("package:utils", search())
unlockBinding("install.packages", pos.to.env(up))
assign("install.packages", utils::install.packages, "package:utils")
lockBinding("install.packages", pos.to.env(up))
})

Best,

luke

On Thu, 21 Mar 2024, Duncan Murdoch wrote:

Yes, you're right.  The version found in the search list entry for 
"package:utils" is the RStudio one; the ones found with two or three colons 
are the original.


Duncan Murdoch

On 21/03/2024 5:48 a.m., peter dalgaard wrote:
Um, what's with the triple colon? At least on my install, double seems to 
suffice:



identical(utils:::install.packages, utils::install.packages)

[1] TRUE

install.packages

function (...)
.rs.callAs(name, hook, original, ...)


-pd


On 21 Mar 2024, at 09:58 , Duncan Murdoch  wrote:

The good news for Jorgen (who may not be reading this thread any more) is 
that one can still be sure of getting the original install.packages() by 
using


utils:::install.packages( ... )

with *three* colons, to get the internal (namespace) version of the 
function.


Duncan Murdoch


On 21/03/2024 4:31 a.m., Martin Maechler wrote:

"Duncan Murdoch on Wed, 20 Mar 2024 13:20:12 -0400 writes:

 > On 20/03/2024 1:07 p.m., Duncan Murdoch wrote:
 >> On 20/03/2024 12:37 p.m., Ben Bolker wrote:
 >>> Ivan, can you give more detail on this? I've heard this
 >>> issue mentioned, but when I open RStudio and run
 >>> find("install.packages") it returns
 >>> "utils::install.packages", and running dump() from
 >>> within RStudio console and from an external "R
 >>> --vanilla" gives identical results.
 >>>
 >>> I thought at one point this might only refer to the GUI
 >>> package-installation interface, but you seem to be
 >>> saying it's the install.packages() function as well.
 >>>
 >>> Running an up-to-date RStudio on Linux, FWIW -- maybe
 >>> weirdness only happens on other OSs?
 >>
 >> On MacOS, I see this:
 >>
 >> > install.packages function (...)  .rs.callAs(name, hook,
 >> original, ...)  
 >>
 >> I get the same results as you from find().  I'm not sure
 >> what RStudio is doing to give a different value for the
 >> function than what find() sees.
 > Turns out that RStudio replaces the install.packages
 > object in the utils package.
 > Duncan Murdoch
Yes, and this has been the case for several years now, and I
have mentioned this several times, too  (though some of it
possibly not in a public R-* mailing list).
And yes, that they modify the package environment
   as.environment("package:utils")
but leave the
   namespace  asNamespace("utils")
unchanged, makes it harder to see what's
going on (but also has less severe consequences; if they kept to
the otherwise universal *rule* that the namespace and package must have 
the same objects

apart from those only in the namespace,
people would not even have access to R's true install.packages()
but only see the RStudio fake^Hsubstitute..
We are still not happy with their decision. Also
help(install.packages) goes to R's documentation of R's
install.packages, so there's even more misleading of useRs.
Martin



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Function environments serialize to a lot of data until they don't

2024-03-08 Thread luke-tierney--- via R-help
ed memory computing in general, so there are various
tools that help. A very simple tool available in the snow package for
snow clusters is snow.time(), which can produce some summary times and
a Gantt chart (patterned after ones produced by xpvm and xmpi). For
example, going back to the first definition of mkLL1 you can try

mkLL1 <- function(m, s) function(x) sum(dnorm(x, m, s, log = TRUE))
ll <- f(1e7)
library(snow)
cl <- makeCluster(2, type = "SOCK")
tm <- snow.time(clusterCall(cl, ll, 1))
print(tm)
plot(tm)
stopCluster(cl)

snow.time() is not very sophisticated, not very well tested, and may
be a bit brittle. It has not been not ported to the parallel package,
but it looks like most of the plumbing is there so porting it might
not be too hard.



If this really is due to promises, what would be the downsides of
forcing them during serialization?


Many. Think NSE, defaults that assume something happens in the body
before the are evaluated ...

Best,

luke

--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Re: Error in setwd(dir) when initializing R

2023-11-20 Thread luke-tierney

On Mon, 20 Nov 2023, Ivan Krylov wrote:


On Mon, 20 Nov 2023 12:18:11 +0100
Ana de las Heras Molina  wrote:


Error in setwd(dir) : no es posible cambiar el directorio de trabajo


If you run traceback() first thing after getting this error, does it
say anything useful? (Anything besides "No traceback available" would
count as useful.)

Do you have a file named .RData in your home directory? If yes, it may
help to move it away (or remove it if you don't use the saved session).


Also check for .Rprofile or other profile that might contain a setwd()
call.  Starting R with --vanilla should work if the issue is a startup
file.

Best,

luke






--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

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

2023-05-18 Thread Calboli Federico (LUKE)
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.


Re: [R] [External] alist() and missing variables

2022-05-02 Thread luke-tierney

On Mon, 2 May 2022, Ivan Krylov wrote:


Hi,

I've been playing around with formals() and stumbled upon some
behaviour which surprised me:

a <- alist(x=)
.Internal(inspect(a$x))
# @55b0ebae67b0 01 SYMSXP g0c0 [MARK,REF(5761)] "" (has value)
x <- a$x
.Internal(inspect(x))
# Error: argument "x" is missing, with no default
missing(x)
[1] TRUE

Apparently, the elements corresponding to formal arguments without a
default value can be passed to functions as arguments (and look like
empty symbols, which can't be created by as.symbol()), but when
assigned to a variable, they turn missing and can't be accessed.

How can I safely detect and work with such values?


You can detect them as you did here using missing(). This is what the
byte code compiler implementation does.
[https://homepage.stat.uiowa.edu/~luke/R/compiler/compiler.pdf]

It's not ideal but it's what we have and not likely to change any time
soon.

Best,

luke






--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Re: Package installation help: Stuck at "** byte-compile and prepare package for lazy loading"

2021-09-30 Thread luke-tierney

When I do full CRAN/BIOC installs I use Xvfb via something like

Xvfb :5 -screen 0 1280x1024x24 &
setenv DISPLAY :5

Best,

luke

On Thu, 30 Sep 2021, Brodie, Kent via R-help 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.


--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Handling interrupts in long-running R functions

2021-09-10 Thread luke-tierney

Some variation of this might do it:

tryCatch(for (i in seq_len(100)) Sys.sleep(1),
 interrupt = function(e) i)

If you want the option to inspect and continue you would need to use
withCallingHandlers and invoke a 'resume' restart.

Best,

luke

On Fri, 10 Sep 2021, Ivan Krylov wrote:


Hello everyone,

I'm writing an R function that may be running for "long" periods of
time (think tens of minutes), and I would like to be able to tell it:
"please stop what you're doing and return the not-yet converged results
as they are for inspection".

The behaviour I'm striving for is

1) User presses interrupt
2) Function handles the interrupt and returns as if the convergence
  test passed
3) By some black magic, the interrupt condition is raised on the
  previous function call level (to avoid the situation where my
  function is called in a loop by some other function and the user
  wants to interrupt the whole process, not just my function).

Is this a good idea? Is (3) even possible? (I guess I could check the
length of sys.parents() and avoid recovering from the interrupt if
called from some other function, but that feels dirty.) Could something
similar be achieved with options(error = recover) and R restarts? Are
there other ways of, well, interrupting the execution of R functions
without changing the semantics of interrupts in R?

I've been working with MATLAB lately (when in Rome, do as Romans
do...), and their idiom for my desired behaviour is "create a plot
window and return when that window is closed", but that doesn't
translate well to R.




--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

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

2021-06-19 Thread luke-tierney

Thanks for the report. Fixed in R-devel in r80530; will port to
R-patched soon.

Best,

luke

On Fri, 18 Jun 2021, Bickis, Mikelis wrote:


Hello:

Here is a bit of R-code:


mvr

[1] 2.2658

(sin(.Last.value)+sin(2*.Last.value))

[1] -0.2156507

acos((-sqrt(17)-1)/8)

[1] 2.2658

(sin(.Last.value)+sin(2*.Last.value))

[1] 1.76745

(sin(mvr)+sin(2*mvr))

[1] -0.2156507




Note that my variable mvr is the value of acos((-sqrt(17)-1)/8).   However, if 
I use .Last.value after invoking the acos function in a further calculation, I 
get a nonsensical result.   What is going on?

I am running R version 4.0.0 (2020-04-24) on an iMac, operating system MacOS 
11.4 “Big Sur”.

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


--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Why is R making a copy-on-modification after using str?

2020-12-02 Thread luke-tierney

On Mon, 30 Nov 2020, luke-tier...@uiowa.edu wrote:


On Mon, 30 Nov 2020, Georg Kindermann wrote:


Dear list members,

I was wondering why R is making a copy-on-modification after using str.

m <- matrix(1:12, 3)
tracemem(m)
#[1] "<0x559df861af28>"
dim(m) <- 4:3
m[1,1] <- 0L
m[] <- 12:1
str(m)
# int [1:4, 1:3] 12 11 10 9 8 7 6 5 4 3 ...
dim(m) <- 3:4  #Here after str a copy is made
#tracemem[0x559df861af28 -> 0x559df838e4a8]:
dim(m) <- 3:4
str(m)
# int [1:3, 1:4] 12 11 10 9 8 7 6 5 4 3 ...
dim(m) <- 3:4 #Here again after str a copy
#tracemem[0x559df838e4a8 -> 0x559df82c9d78]:


As of R 4.0.0 it is in some cases possible to reduce reference counts
internally and so avoid a copy in cases like this. It would be too
costly to try to detect all cases where a count can be dropped, but it
this case we can do better. It turns out that the internals of
pos.to.env were unnecessarily creating an extra reference to the call
environment (here in a call to exists()). This is fixed in r79528.
Thanks.


Also I was wondering why a copy is made when having a Task Callback.

TCB <- addTaskCallback(function(...) TRUE)
m <- matrix(1:12, nrow = 3)
tracemem(m)
#[1] "<0x559dfa79def8>"
dim(m) <- 4:3  #Copy on modification
#tracemem[0x559dfa79def8 -> 0x559dfa8998e8]:
removeTaskCallback(TCB)
#[1] TRUE
dim(m) <- 4:3  #No copy



This _may_ be related to references created in the process of
protecting the return value from evaluation. If so, addressing the
debug issue raised by Duncan may resolve this. If not, someone will
have to take a closer look.


It turns out there were some issues with the way calls to the
callbacks were handled. This has been revised in R-devel in r79541.
This example will no longere need to duplicate in R-devel.

Thanks for the report.

luke



Best,

luke


I am using R version 4.0.3.

Kind regards,
Georg

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

and provide commented, minimal, self-contained, reproducible code.






--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Re: Why is R making a copy-on-modification after using str?

2020-11-30 Thread luke-tierney

On Mon, 30 Nov 2020, Duncan Murdoch wrote:


On 30/11/2020 5:12 a.m., Georg Kindermann wrote:

Dear list members,

I was wondering why R is making a copy-on-modification after using str.


This isn't really an explanation, but adds a bit more data.  If you inspect m 
before and after str(), you'll see that str(m) leaves it with two references:



m <- matrix(1:12, 3)
  .Internal(inspect(m))

@7fcb0ad682c8 13 INTSXP g0c4 [REF(1),ATT] (len=12, tl=0) 1,2,3,4,5,...
ATTRIB:
 @7fcaf5f7b8a0 02 LISTSXP g0c0 [REF(1)]
   TAG: @7fcafd091a80 01 SYMSXP g1c0 [MARK,REF(65535),LCK,gp=0x6000] "dim" 
(has value)

   @7fcb0afecc80 13 INTSXP g0c1 [REF(65535)] (len=2, tl=0) 3,4

  str(m)

int [1:3, 1:4] 1 2 3 4 5 6 7 8 9 10 ...

  .Internal(inspect(m))

@7fcb0ad682c8 13 INTSXP g0c4 [REF(2),ATT] (len=12, tl=0) 1,2,3,4,5,...
ATTRIB:
 @7fcaf5f7b8a0 02 LISTSXP g0c0 [REF(1)]
   TAG: @7fcafd091a80 01 SYMSXP g1c0 [MARK,REF(65535),LCK,gp=0x6000] "dim" 
(has value)

   @7fcb0afecc80 13 INTSXP g0c1 [REF(65535)] (len=2, tl=0) 3,4


It's not just str():  this sequence also does it.

 m <- matrix(1:12, 3)
 debug(mean)
 mean(m)


This is due to the restarts needed by do_browser() creating links to
the environment that could be cleaned up in endcontext. There is a
runtime cost to doing so, but probably worth looking into.

Best,

luke



Hit c a couple of times now to get out of debugging, and m is left with two 
references to it.  I don't see that if mean isn't being debugged.


Duncan Murdoch




m <- matrix(1:12, 3)
tracemem(m)
#[1] "<0x559df861af28>"
dim(m) <- 4:3
m[1,1] <- 0L
m[] <- 12:1
str(m)
# int [1:4, 1:3] 12 11 10 9 8 7 6 5 4 3 ...
dim(m) <- 3:4  #Here after str a copy is made
#tracemem[0x559df861af28 -> 0x559df838e4a8]:
dim(m) <- 3:4
str(m)
# int [1:3, 1:4] 12 11 10 9 8 7 6 5 4 3 ...
dim(m) <- 3:4 #Here again after str a copy
#tracemem[0x559df838e4a8 -> 0x559df82c9d78]:

Also I was wondering why a copy is made when having a Task Callback.

TCB <- addTaskCallback(function(...) TRUE)
m <- matrix(1:12, nrow = 3)
tracemem(m)
#[1] "<0x559dfa79def8>"
dim(m) <- 4:3  #Copy on modification
#tracemem[0x559dfa79def8 -> 0x559dfa8998e8]:
removeTaskCallback(TCB)
#[1] TRUE
dim(m) <- 4:3  #No copy

I am using R version 4.0.3.

Kind regards,
Georg

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



--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics and    Fax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Why is R making a copy-on-modification after using str?

2020-11-30 Thread luke-tierney

On Mon, 30 Nov 2020, Georg Kindermann wrote:


Dear list members,

I was wondering why R is making a copy-on-modification after using str.

m <- matrix(1:12, 3)
tracemem(m)
#[1] "<0x559df861af28>"
dim(m) <- 4:3
m[1,1] <- 0L
m[] <- 12:1
str(m)
# int [1:4, 1:3] 12 11 10 9 8 7 6 5 4 3 ...
dim(m) <- 3:4  #Here after str a copy is made
#tracemem[0x559df861af28 -> 0x559df838e4a8]:
dim(m) <- 3:4
str(m)
# int [1:3, 1:4] 12 11 10 9 8 7 6 5 4 3 ...
dim(m) <- 3:4 #Here again after str a copy
#tracemem[0x559df838e4a8 -> 0x559df82c9d78]:


As of R 4.0.0 it is in some cases possible to reduce reference counts
internally and so avoid a copy in cases like this. It would be too
costly to try to detect all cases where a count can be dropped, but it
this case we can do better. It turns out that the internals of
pos.to.env were unnecessarily creating an extra reference to the call
environment (here in a call to exists()). This is fixed in r79528.
Thanks.


Also I was wondering why a copy is made when having a Task Callback.

TCB <- addTaskCallback(function(...) TRUE)
m <- matrix(1:12, nrow = 3)
tracemem(m)
#[1] "<0x559dfa79def8>"
dim(m) <- 4:3  #Copy on modification
#tracemem[0x559dfa79def8 -> 0x559dfa8998e8]:
removeTaskCallback(TCB)
#[1] TRUE
dim(m) <- 4:3  #No copy



This _may_ be related to references created in the process of
protecting the return value from evaluation. If so, addressing the
debug issue raised by Duncan may resolve this. If not, someone will
have to take a closer look.

Best,

luke


I am using R version 4.0.3.

Kind regards,
Georg

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



--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

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

2020-07-24 Thread luke-tierney

Maybe try something like this:

url <- 
"https://s1.sos.mo.gov/CandidatesOnWeb/DisplayCandidatesPlacement.aspx?ElectionCode=750004975;
h <- xml2::read_html(url)
tbl <- rvest::html_table(h)

Best,

luke

On Fri, 24 Jul 2020, Spencer Graves wrote:


Hi Bill et al.:


  That broke the dam:  It gave me a character vector of length 1 
consisting of 218 KB.  I fed that to XML::readHTMLTable and purrr::map_chr, 
both of which returned lists of 337 data.frames. The former retained names 
for all the tables, absent from the latter.  The columns of the former are 
all character;  that's not true for the latter.



  Sadly, it's not quite what I want:  It's one table for each 
office-party combination, but it's lost the office designation. However, I'm 
confident I can figure out how to hack that.



  Thanks,
  Spencer Graves


On 2020-07-23 17:46, William Michels wrote:

Hi Spencer,

I tried the code below on an older R-installation, and it works fine.
Not a full solution, but it's a start:


library(RCurl)

Loading required package: bitops
url <- 
"https://s1.sos.mo.gov/CandidatesOnWeb/DisplayCandidatesPlacement.aspx?ElectionCode=750004975;

M_sos <- getURL(url)
print(M_sos)

[1] "\r\n\r\n\r\n\r\n\r\n\tSOS, Missouri - Elections:
Offices Filed in Candidate Filing\r\n wrote:

Hello, All:


I've failed with multiple attempts to scrape the table of
candidates from the website of the Missouri Secretary of State:


https://s1.sos.mo.gov/CandidatesOnWeb/DisplayCandidatesPlacement.aspx?ElectionCode=750004975


I've tried base::url, base::readLines, xml2::read_html, and
XML::readHTMLTable; see summary below.


Suggestions?
Thanks,
Spencer Graves


sosURL <-
"https://s1.sos.mo.gov/CandidatesOnWeb/DisplayCandidatesPlacement.aspx?ElectionCode=750004975;

str(baseURL <- base::url(sosURL))
# this might give me something, but I don't know what

sosRead <- base::readLines(sosURL) # 404 Not Found
sosRb <- base::readLines(baseURL) # 404 Not Found

sosXml2 <- xml2::read_html(sosURL) # HTTP error 404.

sosXML <- XML::readHTMLTable(sosURL)
# List of 0;  does not seem to be XML

sessionInfo()

R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.5

Matrix products: default
BLAS:
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK:
/Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets
[6] methods   base

loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2curl_4.3
[4] xml2_1.3.2 XML_3.99-0.3

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



--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Re: read.csv fails in R console in Ubuntu terminal but works in RStudio after R 3.6.3 upgrade to R 4.0.2?

2020-07-16 Thread luke-tierney

On my Ubuntu system the download with read.csv succeeds in an R
console if I set the HTTPUserAgent and download.file.method options to
match the ones used by RStudio.

Given how picky the server is being I would worry about whether this
use is in line with the site's terms of service.

Best,

luke

On Thu, 16 Jul 2020, Ista Zahn wrote:


On Thu, Jul 16, 2020 at 5:15 PM Ista Zahn  wrote:


On Thu, Jul 16, 2020 at 8:18 AM Rui Barradas  wrote:


Hello,

Thanks, but no, download.file still gives 403 Forbidden with both method
= "libcurl" and method = "wget".


I think that makes it "not an R question". Ask on
https://unix.stackexchange.com/ maybe?


Oh, sorry I misread your message. Nevertheless:

$ curl 
"https://old.nasdaq.com/screening/companies-by-name.aspx?letter=0=1=download;

Access Denied

Access Denied

You don't have permission to access
"httpoldnasdaqcomscreeningcompaniesbynameaspx"
on this server.
Reference185506d2171594934303938edcb



$ wget 
"https://old.nasdaq.com/screening/companies-by-name.aspx?letter=0=1=download;
--2020-07-16 17:19:12--
https://old.nasdaq.com/screening/companies-by-name.aspx?letter=0=1=download
Loaded CA certificate '/etc/ssl/certs/ca-certificates.crt'
Resolving old.nasdaq.com (old.nasdaq.com)... 2600:1400:9000:28f::1b46,
2600:1400:9000:29b::1b46, 23.78.161.120
Connecting to old.nasdaq.com
(old.nasdaq.com)|2600:1400:9000:28f::1b46|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2020-07-16 17:19:12 ERROR 403: Forbidden.

I don't think this is an R problem.

Best,
Ista



Best,
Ista



Rui Barradas

Às 05:31 de 16/07/20, Jeff Newmiller escreveu:

Perhaps read FAQ 7.43? [1]

[1] 
https://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-enable-secure-https-downloads-in-R_003f

On July 15, 2020 4:02:27 PM PDT, Rui Barradas  wrote:

Hello,

R 4.0.2 on Ubuntu 20.04 LTS, sessionInfo below.

I'm also unable to read the file with Rscript from the Ubuntu terminal
but the error is not the same as the OP's.


The first try was a file test1.R with the following commands.

x<-"https://old.nasdaq.com/screening/companies-by-name.aspx?letter=0=1=download;
read.csv(x, as.is=TRUE, na="n/a")


And run with Rscript

rui@rui:~$ Rscript --vanilla test1.R
Error in file(file, "rt") :
   cannot open the connection to
'https://old.nasdaq.com/screening/companies-by-name.aspx?letter=0=1=download'
Calls: read.csv -> read.table -> file
In addition: Warning message:
In file(file, "rt") :
   cannot open URL
'https://old.nasdaq.com/screening/companies-by-name.aspx?letter=0=1=download':

HTTP status was '403 Forbidden'
Execution halted



The second try was download.file() and then read it.
File test2.R is:

x<-"https://old.nasdaq.com/screening/companies-by-name.aspx?letter=0=1=download;
download.file(x, "companylist.csv")
read.csv("companylist.csv", as.is=TRUE, na="n/a")


But this too failed with error 403 Forbiden.

rui@rui:~$ Rscript --vanilla test2.R
trying URL
'https://old.nasdaq.com/screening/companies-by-name.aspx?letter=0=1=download'
Error in download.file(x, "companylist.csv") :
   cannot open URL
'https://old.nasdaq.com/screening/companies-by-name.aspx?letter=0=1=download'
In addition: Warning message:
In download.file(x, "companylist.csv") :
   cannot open URL
'https://old.nasdaq.com/screening/companies-by-name.aspx?letter=0=1=download':

HTTP status was '403 Forbidden'
Execution halted


This is my session info.

rui@rui:~$ Rscript --vanilla -e 'sessionInfo()'
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
  [1] LC_CTYPE=pt_PT.UTF-8   LC_NUMERIC=C
  [3] LC_TIME=pt_PT.UTF-8LC_COLLATE=pt_PT.UTF-8
  [5] LC_MONETARY=pt_PT.UTF-8LC_MESSAGES=pt_PT.UTF-8
  [7] LC_PAPER=pt_PT.UTF-8   LC_NAME=C
  [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=pt_PT.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.0.2



Às 08:45 de 15/07/20, Sam H escreveu:

Hi,

I am trying to download some data using read.csv and it works

perfectly in

RStudio and fails in the R console in the terminal in Ubuntu 18.04

after

upgrading from R 3.6.3 to 4.0.2. Before upgrading this worked in the

R

console in the terminal also without any issues.

Why would that be? How to fix this?

Below please find R code output and sessionInfo().

*Works in RStudio*




read.csv("https://old.nasdaq.com/screening/companies-by-name.aspx?letter=0=1=download;,
header=TRUE, as.is=TRUE, na="n/a")

  SymbolName
LastSale MarketCap IPOyear1  

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

2020-06-19 Thread luke-tierney

The behavior has been there much longer than that in R and it's been a
known issue with complex assignment for a long time (not the only
one). You're in a better position than I to know how Splus handles this.

The complex assignment expression

df[, ]$treated <- TRUE

is basically evaluated as

tmp <-df[, ]
tmp$treated <- TRUE
df[,] <- tmp

So the  argument is evaluated twice. This is always a little
inefficient, but probably not what you want if there are side effects
in the index argument. So the main take-away is:

Don't use index arguments with side effects in complex assignments.

It is in principle possible, when standard evaluation is in use, to
capture the value of  from the first evaluation and re-use for
the second. But, for better or worse, assignment methods can and do
use non-standard evaluation for the index arguments, and it would be
very hard for authors of such methods to avoid this. So changing to
avoid multiple index evaluation would always have to come with an
asterisk.

There are other issues with complex assignment as implemented
currently that have higher priority but are also quite tricky to
address. Possibly this one can be addressed at the same time.

Best,

luke

On Fri, 19 Jun 2020, William Dunlap via R-help wrote:


It is a bug that has been present in R since at least R-2.14.0 (the oldest
that I have installed on my laptop).

Bill Dunlap
TIBCO Software
wdunlap tibco.com


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


Hello,


Thanks, I hadn't thought of that.

But, why? Is it evaluated once before assignment and a second time when
the assignment occurs?

To trace both sample and `[<-` gives 2 calls to sample.


trace(sample)
trace(`[<-`)
df[sample(nrow(df), 3),]$treated <- TRUE
trace: sample(nrow(df), 3)
trace: `[<-`(`*tmp*`, sample(nrow(df), 3), , value = list(unit = c(7L,
6L, 8L), treated = c(TRUE, TRUE, TRUE)))
trace: sample(nrow(df), 3)


Regards,

Rui Barradas


Às 17:20 de 19/06/2020, William Dunlap escreveu:

The first subscript argument is getting evaluated twice.

trace(sample)
set.seed(2020); df[i<-sample(10,3), ]$Treated <- TRUE

trace: sample(10, 3)
trace: sample(10, 3)

i

[1]  1 10  4

set.seed(2020); sample(10,3)

trace: sample(10, 3)
[1] 7 6 8

sample(10,3)

trace: sample(10, 3)
[1]  1 10  4

Bill Dunlap
TIBCO Software
wdunlap tibco.com <http://tibco.com>


On Fri, Jun 19, 2020 at 8:46 AM Rui Barradas mailto:ruipbarra...@sapo.pt>> wrote:

Hello,

I don't have an answer on the reason why this happens but it seems
like
a bug. Where?

In which of  `[<-.data.frame` or `[<-.default`?

A solution is to subset and assign the vector:


set.seed(2020)
df2 <- data.frame(unit = 1:10)
df2$treated <- FALSE

df2$treated[sample(nrow(df2), 3)] <- TRUE
df2
#  unit treated
#1 1   FALSE
#2 2   FALSE
#3 3   FALSE
#4 4   FALSE
#5 5   FALSE
#6 6TRUE
#7 7TRUE
#8 8TRUE
#9 9   FALSE
#10   10   FALSE


Or


set.seed(2020)
df3 <- data.frame(unit = 1:10)
df3$treated <- FALSE

df3[sample(nrow(df3), 3), "treated"] <- TRUE
df3
# result as expected


Hope this helps,

Rui  Barradas



Às 13:49 de 19/06/2020, Sébastien Lahaie escreveu:
   > I ran into some strange behavior in R when trying to assign a
treatment to
   > rows in a data frame. I'm wondering whether any R experts can
explain
   > what's going on.
   >
   > First, let's assign a treatment to 3 out of 10 rows as follows.
   >
   >> df <- data.frame(unit = 1:10)
   >> df$treated <- FALSE
   >> s <- sample(nrow(df), 3)
   >> df[s,]$treated <- TRUE
   >> df
   > unit treated
   >
   > 1 1   FALSE
   >
   > 2 2TRUE
   >
   > 3 3   FALSE
   >
   > 4 4   FALSE
   >
   > 5 5TRUE
   >
   > 6 6   FALSE
   >
   > 7 7TRUE
   >
   > 8 8   FALSE
   >
   > 9 9   FALSE
   >
   > 10   10   FALSE
   >
   > This is as expected. Now we'll just skip the intermediate step
of saving
   > the sampled indices, and apply the treatment directly as follows.
   >
   >> df <- data.frame(unit = 1:10)
   >> df$treated <- FALSE
   >> df[sample(nrow(df), 3),]$treated <- TRUE
   >> df
   > unit treated
   >
   > 1 6TRUE
   >
   > 2 2   FALSE
   >
   > 3 3   FALSE
   >
   > 4 9TRUE
   >
   > 5 5   FALSE
   >
   > 6 6   FALSE
   >
   > 7 7   FALSE
   >
   > 8 5TRUE
   >
   > 9 9   FALSE
   >
   > 10   10   FALSE
   >
   > Now the data frame still has 10 rows with 3 assigned to the
treatment. But
   > the units are garbled. Units 1 an

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

2020-05-09 Thread luke-tierney

Since you asked ...

There are two different use cases for stopifnot: in tests and
in implementation code.

stopifnot seems to be optimized for the test code case where speed and
clarity may not be that important.

For expresing assertions in implemantation code clarity and simplicity
are important. What I would want is something equivalent to

stpifnt0 <- function(e)
if (! isTRUE(e))
stop(deparse(exprs[i]), "is not true")

(maybe with some additional gettetxt/deparse/call fiddling magic, but
only _after_ the fail, not on the hot path for a passed test.)

I would not want to have to worry about fine print about whether there
is an implicit 'all' for an expression returning a vector, or whether
that is really an 'all' or a variant that treate the empty set
differently.

I might consider a multiargument verison along the lines of

stpfnt <- function(...) {
exprs <- as.list(substitute(list(...)))[-1]
for (i in seq_along(exprs))
if (! isTRUE(...elt(i)))
stop(deparse(exprs[i]), "is not true")
}

But I think in most cases I rather write two separate assertions.

The advantage of stpfnt0 is code is that it is more concise than
writing out the test and the code to produce an error message,
especially a nice one. But it this comes at a big performance cost
then using it would be harder to jsutify.

With simple semantics like the stpfnt0 definition here the compiler
could be taught to optimize it's use to cost little more than the test
in the passing case. That gets harder the more complexity is added to
stopifnot.

We could add a simpler stopifnot0, but I'm not sure I want to go
there.

Best,

luke

On Sat, 9 May 2020, Martin Maechler wrote:


Martin Maechler
on Mon, 13 Apr 2020 22:30:35 +0200 writes:



William Dunlap
on Mon, 13 Apr 2020 09:57:11 -0700 writes:


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


well, maybe.



As I brought up the 0-length example:  One could think of making
an exception for  logical(0)  and treat that as non-TRUE.



(for R-devel only, [..])



Martin


I have been a bit sad that nobody (not even Hervé) reacted to my
proposal, 4 weeks ago.

As I agree that it is safer for stopifnot() to be less lenient
here, and not allow the usual behavior of logical(0) to be
treated as TRUE, namely  as in   all(logical(0))  |-->  TRUE ,
I had actually implemented the above proposal in my own version of R-devel,
(but not committed!), nicely introducing a new optional argument
'allow.logical0'  where

- allow.logical0 = FALSE  is the new default

- allow.logical0 = TRUE   is back compatible

What I found is that this (not back compatible) change lead to a
few test breakages also in R & recommended packages, and IIRC in
a few of my own packages.  Still probably only in about 1 in 1000
of the stopifnot cases, but in practically all cases, the breakage was
"wrong" in the sense that {conceptual example}

 stopifnot( f1(x) == f2(x) )

should test (almost, say apart from names(.)) identical behavior
of f1() and f2()  and that would naturally also extend to the
case of 0-extent 'x'.

So I had to change the above (half a dozen, say) cases to

   stopifnot( f1(x) == f2(x) , allow.logical0 = TRUE)

to keep the test working as it was intended to.
The nice thing about the change is that it is also working in
current versions of R  where  allow.logical is not a special
argument and just treated as part of '...' and is it TRUE, does
not change the semantic of stopifnot() in current (possibly,
then, "previous") versions of R.

Overall I think it may be a good idea to consider this
not-back-compatible change to  stopifnot()
 (if only to get Hervé into continue using it ! ;-) ;-))

BUT  I assume quite a few other people may have to get used to
see the following error in their stopifnot() code and will have
to add  occasional   'allow.logical0 = TRUE'  to those cases the
old behavior was really the intended one.

(I will have to finally get Matrix 1.3-0 released to CRAN
before committing the change to R-devel,  and I may also ask
help of someone to check all CRAN/Bioc against that change so I
can alert package authors who need to adapt).

Please let us know your thoughts on this.

Martin



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

   >>>
   >>>
   >>> On 4/13/20 05:30, Martin Maechler wrote:
   >>> >>>>>> peter dalgaard
   >>> >>>>>>  on Mon, 13 Apr 2020 12:00:38 +0200 writes:
   >>> >
   >>> >  > Inline...
   >>> >  >> On 13 Apr 2020, at 11:15 , Martin Maechler <
   &g

Re: [R] [External] Re: Error in colouring by group in core plot R

2020-04-24 Thread luke-tierney

Or using matplot:

matplot(cbind(g1, g2, g3), type = "l",
col = c("red", "black", "blue"), lty = 1, lwd = 2)

Best,

luke

On Fri, 24 Apr 2020, Jim Lemon wrote:


Hi Luigi,
This is pretty easy using "plot" and "lines":

# assume your example data
plot(g1,col ="red",type = "l", lwd = 2,
xlab = "Days since start", ylab = "Count of infections",
main = "Daily cases of COVID-19")
lines(g2,col="black", lwd = 2)
lines(g3,col="blue", lwd = 2)
text(c(15,80,53),rep(6000,3),
c("China","Germany","Italy"),col=c("red","black","blue"))

Jim

On Fri, Apr 24, 2020 at 5:25 PM Luigi Marongiu  wrote:


Hello,
I am trying to make an epidemic plot of the COVID pandemic using the core
plot function. I am looking at three countries and the countries are as
factors. The idea is to colour the entry by country, following this scheme:
```
df = data.frame(index = 1:10,
value = c(rnorm(10), rnorm(10), rnorm(10)),
set = c(rep("Group 1", 3), rep("Group 2", 3), rep("Group
3", 4)))
plot(df$index ~ df$value, col=c("blue", "orange", "purple")[df$set])
```
But in the actual graph there is only one colour:
```
Index = c(1:101)
g1 = c(0,259,457,688,769,1771,1459,1737,1981,2099,2589,2825,3235,3884,3694,

 3143,3385,2652,2973,2467,2015,14108,5090,2641,2008,2048,1888,1749,391,
   889,823,648,214,508,406,433,327,427,573,202,125,119,139,143,99,44,40,

 0,0,0,0,0,0,0,0,0,0,0,0,46,39,78,47,67,55,54,45,0,79,36,35,0,0,0,39,0,
   0,63,42,46,99,108,89,46,46,0,325,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
g2 =
c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
   0,0,0,0,0,0,0,59,283,125,130,240,184,341,401,779,930,924,1214,1459,
   2095,2960,2993,4528,2516,2509,4183,3935,4332,6615,6933,6824,4740,
   4450,4923,6173,6813,6365,4933,4031,3252,4288,5633,4939,3936,3281,
   2402,2218,2138,2543,2945,3699,2327,2018,1323,1388,2195,2481,0,0,
   0,0,0,0,0,0)
g3= c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,58,
  78,72,94,147,185,234,239,573,335,466,587,769,778,1247,1492,1797,977,
  2313,2651,2547,3497,3590,3233,3526,4207,5322,5986,6557,5560,4789,
  5249,5210,6203,5909,5974,5217,4050,4053,4782,4668,4585,4805,4316,
  3599,3039,3836,4204,3951,4694,4092,3153,3961,2667,3786,3493,3491,
  3047,2256,2729,3370,2646,0,0,0,0,0,0,0,0)
Incidence = c(g1, g2, g3)
Country = c(rep("China", length(Index)), rep("Germany", length(Index)),
rep("Italy", length(Index)))
df = data.frame(Index, Incidence, Country)
plot(df$Incidence ~ df$Index,
 col = c("red", "black", "blue")[df$Country],
 type = "l", lwd = 2,
 xaxt = "n",
 xlab = expression(bold("Date")),
 ylab = expression(bold("Incidence")),
 main = "Raw values")
```

What am I missing?
Thank you

--
Best regards,
Luigi

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



--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

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

2019-07-24 Thread Tierney, Luke
Thanks Roy -- I was about to write along the same lines.

Best,

luke

On Wed, 24 Jul 2019, Roy Mendelssohn - NOAA Federal via R-help wrote:

> Hi Rolf:
>
> As they say,  do read the posting guide:
>
>> Good manners: Remember that customs differ. Some people are very direct. 
>> Others surround everything they say with hedges and apologies. Be tolerant. 
>> Rudeness is never warranted, but sometimes `read the manual’ is the 
>> appropriate response. Don’t waste time discussing such matters on the list. 
>> Ad hominem comments are absolutely out of place.
>
>
> -Roy
>
>
>>
>> On Jul 24, 2019, at 2:49 PM, Rolf Turner  wrote:
>>
>>
>> On 25/07/19 4:36 AM, Weiwen Ng, MPH wrote:
>>
>>> Here's one way to phrase your reply:
>>> "I'd recommend you search Google. For example, the search string
>>> "proprietary use GPL" produces one hit that's clearly relevant to you:
>>
>> 
>>
>>> This method is more neutrally worded. It doesn't insult the original
>>> poster. It doesn't assume the poster had bad intent.
>>> Instead, you chose to phrase it thus:
>>> "Your internet skills are pathetic. Search Google for "proprietary use gpl"
>>> and the first hit is ...  Note that there are (at least) three obvious
>>> alternatives if there is any question in your case ...   I think your
>>> desperation to steal the hard work of the various R contributors seems
>>> quite odious."
>>> Think about the overall tone of your post. Consider also that someone who
>>> agrees with you substantive argument said that your comments were "often
>>> (almost always?) a bit rough about the edges."
>>
>> Yeah, but Jeff's rough-about-the-edges phrasing is much more colourful, and 
>> colourful is *GOOD*.  There is far too much bland "S. We *mustn't* 
>> offend anybody" content in current discourse.  Tell it like it is!  Ripley 
>> into people!  If the recipient can't take the heat, he or she should get out 
>> of the kitchen!
>>
>> See also fortunes::fortune(87).
>>
>> cheers,
>>
>> Rolf Turner
>>
>> P.S.  Jeff makes a huge and extremely useful contribution to R-help.  He 
>> gives generously of time and effort to solve beginners' problems.  They 
>> should appreciate the time and effort and not whinge about being offended.
>>
>> R. T.
>>
>> --
>> 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.
>
> **
> "The contents of this message do not reflect any position of the U.S. 
> Government or NOAA."
> **
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new street address***
> 110 McAllister Way
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK Jr.
>
> ______
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Re: R 3.6.1 and apcluster package

2019-07-18 Thread Tierney, Luke
On Thu, 18 Jul 2019, Jan Galkowski wrote:

> I have confirmed that a complete workaround to these problems is available 
> if, as Bill Dunlap suggested, "version=2" is used in all *save* incantations.

That will mask this particular symptom, but the real problem is that
the C++ code in the package is mutating an object that it should
duplicate first. I'm not sure if the problem should be addressed in
the package or in Rcpp, but one of the two should be fixed.

The specific problem is in the source file
apcluster/src/aggExClusterC.cpp lines 160-161:

 IntegerVector newClust = concat(actClust[I], actClust[J]);
 newClust.names() = CharacterVector(newClust);

The call CharacterVector(newClust) produced a deferred string object
for newClust and marks newClust as immutable, but the assignment
ignores that and mutates anyway. I have CC'd the maintainers of
apcluster and Rcpp.

We may be able to make serialize() and .Internal(inspect()) a bit more
robust to this sort of misbehavior in package space, but as more
optimizations are added package authors who use native code will need
to be more careful about adhering to the rules for when objects can be
safely modified.

Best,

luke

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

Re: [R] [External] Re: R 3.6.1 and apcluster package

2019-07-18 Thread Tierney, Luke
Something about the deferred string conversion object in

a <- names(attributes(apresX)[[4]][[1]][[1]])

is malformed; .Internal(inspect(a)) also infinite loops.
Will try to narrow this down.

Best,

luke

On Thu, 18 Jul 2019, William Dunlap via R-help wrote:

> If you use version=3, ascii=TRUE and look at the file made up to the point
> of the error, you can see a quasi-infinite repeat of a block of 165 numbers
> (after a deferred string called "base"?).  Looks like inappropriate
> recursion.
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Thu, Jul 18, 2019 at 7:38 AM William Dunlap  wrote:
>
>> Note that you can reproduce this in R-3.5.1 if you specify serialization
>> version 3 (which became the default in 3.6.0).
>>
>>> save(apresX, file="351-2.RData", version=2)
>>> save(apresX, file="351-2.RData", version=3)
>> Error: C stack usage  7969184 is too close to the limit
>>> version$version.string
>> [1] "R version 3.5.1 (2018-07-02)"
>>
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>>
>> On Thu, Jul 18, 2019 at 12:46 AM Jan Galkowski 
>> wrote:
>>
>>>> # Test for saving. Jan Galkowski, 17th July 2019.
>>>> # produceProtectionFault.R
>>>>
>>>> library(apcluster)
>>>> cl1 <- cbind(rnorm(100, 0.2, 0.05), rnorm(100, 0.8, 0.06))
>>>> cl2 <- cbind(rnorm(50, 0.7, 0.08), rnorm(50, 0.3, 0.05))
>>>> x <- rbind(cl1, cl2)
>>>>
>>>> ## compute similarity matrix and run affinity propagation
>>>> ## (p defaults to median of similarity)
>>>> simil<- negDistMat(x, r=2)
>>>> apres <- apcluster(s=simil, details=TRUE)
>>>> apresX<- aggExCluster(s=simil, x=apres)
>>>>
>>>> show(apres)
>>>> show(apresX)
>>>>
>>>> saveRDS(object=apresX, file="foo.rds", compress=TRUE)
>>>>
>>>> #save(apresX, file="bar.data", compress=TRUE)
>>>>
>>>> #save.image("crazy.RData")
>>>
>>> The example is from the apcluster documentation. Leaving any one of the
>>> "save"s uncommented produces said fault.
>>>
>>>  - Jan
>>>
>>> On Wed, Jul 17, 2019, at 08:18, Jeff Newmiller wrote:
>>>> It would never make sense for such messages to reflect normal and
>>> expected operation, so hypothesizing about intentionally changing stack
>>> behavior doesn't make sense.
>>>>
>>>> The default format for saveRDS changed in 3.6.0. There may be bugs
>>> associated with that, but rolling back to 3.6.0 would just trade bugs.
>>>>
>>>> https://cran.r-project.org/doc/manuals/r-devel/NEWS.html
>>>>
>>>> On July 16, 2019 8:56:28 PM CDT, Jan Galkowski <
>>> bayesianlogi...@gmail.com> wrote:
>>>>> Did something seriously change in R 3.6.1 at least for Windows in terms
>>>>> of stack impacts?
>>>>>
>>>>> I'm encountering many problems with the 00UNLOCK, needing to disable
>>>>> locking during installations.
>>>>>
>>>>> And I'm encountering
>>>>>
>>>>>> Error: C stack usage 63737888 is too close to the limit
>>>>>
>>>>> for cases I did not before, even when all I'm doing is serializing an
>>>>> object to be saved with *saveRDS* or even *save.image(.)*.
>>>>>
>>>>> Yes, I know, I did not append a minimally complete example. Just wanted
>>>>> to see if it was just me, or if anyone else was seeing this.
>>>>>
>>>>> It's on Windows 7 HE and I've run *R* here for years.
>>>>>
>>>>> My inclination is to drop back to 3.6.0 if it is just me or if no one
>>>>> knows about this problem.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> - Jan Galkowski.
>>>>>
>>>>>
>>>>> [[alternative HTML version deleted]]
>>>>>
>>>>> __
>>>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>> PLEASE do read the posting guide
>>>>> http://www.R-project.org/posting-guide.html
>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>> --
>&

Re: [R] [External] Re: Problem with random numbers/seed

2019-06-21 Thread Tierney, Luke
Maybe looking at ?suppressWarnings will make you feel better.

Best,

luke

On Fri, 21 Jun 2019, Steven Yen wrote:

> Unhappy but thanks.
> Steven
>
> On 6/22/2019 1:13 AM, Uwe Ligges wrote:
>>
>>
>> On 21.06.2019 19:09, Steven Yen wrote:
>>> Now I see that results were replicated but running RNGversion
>>> I get a warning message. Isn't there a way to do this clean?
>>
>> Well, the old RNG is known to be not optimal, hence we give a warning
>> if you choose the old one. This is the clean way if you really want to
>> get the old (slightly buggy) behaviour.
>>
>> Best,
>> Uwe Ligges
>>
>>>
>>>> RNGversion("3.5.3") Warning message: In RNGkind("Mersenne-Twister",
>>> "Inversion", "Rounding") : non-uniform 'Rounding' sampler used
>>>
>>>
>>> On 6/22/2019 1:03 AM, Uwe Ligges wrote:
>>>> What does not work?
>>>>
>>>>
>>>> For me it works under R-3.6.0:
>>>>
>>>>   x<-1:500
>>>>   set.seed(12345671)
>>>>   j<-sample(1:length(x),size=60); y<-x[j]
>>>>   summary(j)
>>>>
>>>>   RNGversion("3.5.3")
>>>>   set.seed(12345671)
>>>>   j<-sample(1:length(x),size=60); y<-x[j]
>>>>   summary(j)
>>>>
>>>>
>>>> Now I get the results you got udner the old R.
>>>>
>>>> Best,
>>>> Uwe Ligges
>>>>
>>>>
>>>>
>>>> On 21.06.2019 18:39, Steven Yen wrote:
>>>>> Thanks. Somewhat of a mystery. The older version I had was
>>>>> R-3.5.3patched.
>>>>> I cannot get the RNGversion command to run. Can you help? Thanks.
>>>>>
>>>>> On 6/22/2019 12:25 AM, Uwe Ligges wrote:
>>>>>> See the NEWS, the RNG has been changed, use RNGversion
>>>>>>
>>>>>> On 21.06.2019 18:10, Steven Yen wrote:
>>>>>>> Dear all,
>>>>>>> I did all this work with older R (R-3.5.3.patched and older)
>>>>>>> but now with R3.6 I cannot replicate the results.
>>>>>>> Below I sample 60 observations from 1:500 using the sample command
>>>>>>> with
>>>>>>> a random seed of 123. I get different results. Advice appreciated.
>>>>>>> Steven Yen
>>>>>>>
>>>>>>>    > # Run under R-3.6.0
>>>>>>>    > x<-1:500
>>>>>>>    > set.seed(12345671)
>>>>>>>    > j<-sample(1:length(x),size=60); y<-x[j]
>>>>>>>    > summary(y)
>>>>>>>       Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>>>>>>>       26.0   134.2   240.0   249.8   368.0   500.0
>>>>>>>
>>>>>>>    > # Run under R-3.5.3.patched
>>>>>>>    > x<-1:500
>>>>>>>    > set.seed(12345671)
>>>>>>>    > j<-sample(1:length(x),size=60); y<-x[j]
>>>>>>>    > summary(y)
>>>>>>>       Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>>>>>>>        9.0   122.2   205.0   236.1   364.2   493.0
>>>>>>>
>>>>>>
>>>>>>
>>>>>> Under R-3.6.0  use, e.g.
>>>>>> RNGversion("3.5.2")
>>>>>> to get reproducible results from the older RNG.
>>>>>>
>>>>>> Best,
>>>>>> Uwe Ligges
>>>>>>
>>>>>>
>>>>>
>>>>> --
>>>>> st...@ntu.edu.tw  (S.T. Yen)
>>>>>
>>>>
>>>
>>
>
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Question about behavior of sample.kind in set.seed (R 3.6)

2019-04-14 Thread Tierney, Luke
Thanks for the report. The sample.kind argument was not being passed
on to the .Internal. This is now fixed in R-devel and the R 3.6.0
branch.

Best,

luke

On Fri, 12 Apr 2019, Elizabeth Purdom wrote:

> Hello,
>
> I am trying to update a package for the upcoming release of R, and my unit 
> tests are affected by the change in the sample. I understand that to 
> reproduce the old sampling, I need to set sample.kind=“Rounding” in RNGkind 
> or set.seed. But I am confused by the behavior of the sample.kind argument in 
> set.seed, as it doesn’t seem to change my results.
>
> In particular, I was trying to understand what happens if you make a call to 
> set.seed within a function to the global environment. So I set up a test as 
> follows:
>
> ###Test set.seed
> f<-function(n,sample.kind){   #="Rounding" or "Rejection"
>   cat("RNG at beginning\n")
>   print(RNGkind())
>   # RNGkind(sample.kind=sample.kind)
>   # cat("RNG at after set\n")
>   # print(RNGkind())
>   set.seed(23,sample.kind=sample.kind)
>   cat("RNG at after set seed\n")
>   print(RNGkind())
>   sample(1:40,size=n,replace=TRUE)
> }
>
> RNGkind(sample.kind="Rejection”)
> print(RNGkind())
> n<-100
> y<-f(n,"Rounding”)
> print(RNGkind())
> y2<-f(n,"Rejection”)
> print(RNGkind())
> all(y==y2)
>
> However, it didn’t do anything:
>> RNGkind(sample.kind="Rejection")
>> print(RNGkind())
> [1] "Mersenne-Twister" "Inversion""Rejection"
>> n<-100
>> y<-f(n,"Rounding")
> RNG at beginning
> [1] "Mersenne-Twister" "Inversion""Rejection"
> RNG at after set seed
> [1] "Mersenne-Twister" "Inversion""Rejection"
> Warning message:
> In set.seed(23, sample.kind = sample.kind) :
> non-uniform 'Rounding' sampler used
>> print(RNGkind())
> [1] "Mersenne-Twister" "Inversion""Rejection"
>> y2<-f(n,"Rejection")
> RNG at beginning
> [1] "Mersenne-Twister" "Inversion""Rejection"
> RNG at after set seed
> [1] "Mersenne-Twister" "Inversion""Rejection"
>> print(RNGkind())
> [1] "Mersenne-Twister" "Inversion""Rejection"
>> all(y==y2)
> [1] TRUE
>
> If I run the same test with calls to RNGkind, however, it does change the 
> method (and I discovered in answer to my question, it appears to change the 
> global method, which is an unfortunate fact for what I am trying to do).
>
> ###Test RNGkind
> f<-function(n,sample.kind){   #="Rounding" or "Rejection"
>   cat("RNG at beginning\n")
>   print(RNGkind())
>   RNGkind(sample.kind=sample.kind)
>   cat("RNG at after set\n")
>   print(RNGkind())
>   set.seed(23)
>   cat("RNG at after set seed\n")
>   print(RNGkind())
>   sample(1:40,size=n,replace=TRUE)
> }
>
> RNGkind(sample.kind="Rejection”)
> print(RNGkind())
> n<-100
> y<-f(n,"Rounding”)
> print(RNGkind())
> y2<-f(n,"Rejection”)
> print(RNGkind())
> all(y==y2)
>
>> RNGkind(sample.kind="Rejection")
>> print(RNGkind())
> [1] "Mersenne-Twister" "Inversion""Rejection"
>> n<-100
>> y<-f(n,"Rounding")
> RNG at beginning
> [1] "Mersenne-Twister" "Inversion""Rejection"
> RNG at after set
> [1] "Mersenne-Twister" "Inversion""Rounding"
> RNG at after set seed
> [1] "Mersenne-Twister" "Inversion""Rounding"
> Warning message:
> In RNGkind(sample.kind = sample.kind) : non-uniform 'Rounding' sampler used
>> print(RNGkind())
> [1] "Mersenne-Twister" "Inversion""Rounding"
>> y2<-f(n,"Rejection")
> RNG at beginning
> [1] "Mersenne-Twister" "Inversion""Rounding"
> RNG at after set
> [1] "Mersenne-Twister" "Inversion""Rejection"
> RNG at after set seed
> [1] "Mersenne-Twister" "Inversion""Rejection"
>> print(RNGkind())
> [1] "Mersenne-Twister" "Inversion""Rejection"
>> all(y==y2)
> [1] FALSE
>
> So clearly I should use RNGkind to change it, but what is the argument 
> actually doing in set.

Re: [R] Genuine relative paths with R

2018-10-10 Thread Tierney, Luke
If you are always running your main script as 'Rscript myscript.R'
then your file argument will appear as '--file=myscript.R' in
commandArgs(). So you can use something like

scriptFile <- function()
{
 pat <- "^--file="
 args <- commandArgs()
 file <- args[grepl(pat, args, args)]
 normalizePath(sub(pat, "", file))
}

Then scriptFile() will give you something to work with.

Best,

luke



On Wed, 10 Oct 2018, Olivier GIVAUDAN wrote:

> Dear Eik,
>
> Thank you for your message.
>
> Yes, I already got to know this package and this discussion (while I found 
> the 'here' package). But thanks.
>
> Best regards,
>
> Olivier
> 
> De : Eik Vettorazzi 
> Envoy??? : lundi 8 octobre 2018 11:30
> ??? : Olivier GIVAUDAN; r-help@r-project.org
> Objet : Re: [R] Genuine relative paths with R
>
> Dear Olivier,
> you may find the rprojroot package useful, see
> https://github.com/r-lib/rprojroot
>
> and a discussion
>
> https://gist.github.com/jennybc/362f52446fe1ebc4c49f#file-2014-10-12_stop-working-directory-insanity-md
>
> Cheers
>
> Am 06.10.2018 um 13:48 schrieb Olivier GIVAUDAN:
>> Dear R users,
>>
>> I would like to work with genuine relative paths in R for obvious reasons: 
>> if I move all my scripts related to some project as a whole to another 
>> location of my computer or someone else's computer, if want my scripts to 
>> continue to run seamlessly.
>>
>> What I mean by "genuine" is that it should not be necessary to hardcode one 
>> single absolute path (making the code obviously not "portable" - to another 
>> place - anymore).
>>
>> For the time being, I found the following related posts, unfortunately never 
>> conclusive or even somewhat off-topic:
>> https://stackoverflow.com/questions/1815606/rscript-determine-path-of-the-executing-script
>> https://stackoverflow.com/questions/47044068/get-the-path-of-current-script/47045368
>> http://r.789695.n4.nabble.com/Script-auto-detecting-its-own-path-td2719676.html
>>
>> So I found 2 workarounds, more or less satisfactory:
>>
>>
>>1.  Either create a variable "ScriptPath" in the first lines of each of 
>> my R scripts and run a batch (or shell, etc.) to replace every single 
>> occurrence of "ScriptPath <-" by "ScriptPath <- [Absolute path of the R 
>> script]" in all the R scripts located in the folder (and possibly 
>> subfolders) of the batch file.
>>2.  Or create an R project file with RStudio and use the package "here" 
>> to get the absolute path of the R project file and put all the R scripts 
>> related to this project in the R project directory, as often recommended.
>>
>> But I am really wondering why R doesn't have (please tell me if I'm wrong) 
>> this basic feature as many other languages have it (batch, shell, C, LaTeX, 
>> SAS with macro-variables, etc.)?
>> Do you know whether the language will have this kind of function in a near 
>> future? What are the obstacles / what is the reasoning for not having it 
>> already?
>>
>> Do you know other workarounds?
>>
>> Best regards,
>>
>> Olivier
>>
>>[[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.
>>
>
> --
> Eik Vettorazzi
>
> Department of Medical Biometry and Epidemiology
> University Medical Center Hamburg-Eppendorf
>
> Martinistrasse 52
> building W 34
> 20246 Hamburg
>
> Phone: +49 (0) 40 7410 - 58243
> Fax:   +49 (0) 40 7410 - 57790
> Web: www.uke.de/imbe<http://www.uke.de/imbe>
> --
>
> _
>
> Universit???tsklinikum Hamburg-Eppendorf; K???rperschaft des ???ffentlichen 
> Rechts; Gerichtsstand: Hamburg | www.uke.de
> Vorstandsmitglieder: Prof. Dr. Burkhard G???ke (Vorsitzender), Prof. Dr. Dr. 
> Uwe Koch-Gromus, Joachim Pr???l???, Martina Saurin (komm.)
> _
>
> SAVE PAPER - THINK BEFORE PRINTING
>
>   [[alternative HTML version deleted]]
>
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] glmer won't allow quasi- distribution mixed models

2018-07-09 Thread Luke Duncan
Dear R folk

I am trying to run a series of models on distance data for three different
species of animals. My data are not zero-inflated (distances were recorded
for locomotion only and so if the animal didn't move, it wasn't recorded)
and are Poisson distributed. However, all of the models that I run are
horrifically over-dispersed and based on what I read online I thought that
maybe I should consider using a quasi-Poisson distribution to attempt to
account for the over-dispersion. All the online posts of others show that
they do so successfully but for some reason, my lme4 package cannot use
quasi-distributions. I have uninstalled and reinstalled R and the packages
and I still get the same problem.

I am

a) at a loss as to how to deal with the over-dispersion I have and
b) baffled by the fact that lme4 everywhere else can cope with
quasi-distributions but mine can't.

Any help would be appreciated!

My code:

library(lme4)
woodlicedata<-read.csv("Woodlice.csv",header=T)
attach(woodlicedata)
names(woodlicedata)
> ### This set of models examine whether there are differences in distances
travelled.
>
distmodel<-glmer(Distance~Treatment*Sex+(1|ID)+(1|Path.set/ID),family=poisson(link='log'))
> summary(distmodel)  ### AIC= 42972.6
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) [
glmerMod]
 Family: poisson  ( log )
Formula: Distance ~ Treatment * Sex + (1 | ID) + (1 | Path.set/ID)

 AIC  BIC   logLik deviance df.resid
 42972.6  43007.3 -21479.3  42958.6 1038

Scaled residuals:
Min  1Q  Median  3Q Max
-11.853  -4.074  -1.656   2.146  38.035

Random effects:
 Groups  NameVariance  Std.Dev.
 ID:Path.set (Intercept) 6.485e-02 0.2546560
 ID  (Intercept) 6.906e-02 0.2627973
 Path.set(Intercept) 1.368e-10 0.117
Number of obs: 1045, groups:  ID:Path.set, 104; ID, 52; Path.set, 2

Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept)  4.208140.07757  54.248  < 2e-16 ***
TreatmentRestricted  0.108430.14359   0.755  0.45015
SexMale -0.084080.11545  -0.728  0.46644
TreatmentRestricted:SexMale -0.493000.18781  -2.625  0.00866 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
(Intr) TrtmnR SexMal
TrtmntRstrc -0.540
SexMale -0.672  0.363
TrtmntRs:SM  0.413 -0.765 -0.615

>
distmodel2<-glmer(Distance~Treatment*Sex+(1|ID)+(1|Path.set/ID),family=quasipoisson(link='log'))
Error in lme4::glFormula(formula = Distance ~ Treatment * Sex + (1 | ID) +
:
  "quasi" families cannot be used in glmer

[[alternative HTML version deleted]]

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


Re: [R] R 3.5.0, vector memory exhausted error on readBin

2018-06-12 Thread luke-tierney

On Tue, 12 Jun 2018, Valerie Cavett wrote:


Ah - I see the problem - thanks so much for the clarification!

Just in case anyone else is using Rstudio on a mac and runs into this issue, I 
ended up following the instructions from
http://btibert3.github.io/2015/12/08/Environment-Variables-in-Rstudio-on-Mac.html

to add the following line to the .Renviron file:
R_MAX_VSIZE=700Gb



And, also for the record, I advise not to do this. It may be an
adequate quick fix for your setting for now, but it loses the
protection the default provides, and it means your code will only work
on a Linux or Windows system with well above half a terabyte of
memory.

Best,

luke


On restart (R 3.5.0), this did the trick and the files read normally.

Thanks again for all the assistance!
Val




From: luke-tier...@uiowa.edu 
Sent: Tuesday, June 12, 2018 10:14 AM
To: Valerie Cavett
Cc: r-help@R-project.org
Subject: Re: [R] R 3.5.0, vector memory exhausted error on readBin


??

The environment variable R_MAX_VSIZE is read at start-up so need to be
set outside R. If you are starting R from a shell you can use

 env R_MAX_VSIZE=700Gb R

If you use a GUI you might need to set the variable in another
way.

Here is a reproducible version of your example:

 hertz <- 6000
 binfile <- tempfile()
 writeBin(1L, binfile, size = 2)
 v <- readBin(binfile, integer(), size = 2, n = 8*hertz*60*6)
 unlink(binfile)

With the limit raised to 700Gb or more this will work in R 3.5.0
but you lose the protection of the lower default setting. You need a
value that high because your 'n' value is asking readBin to allocate a
buffer 643.7 Gb. Mac OS lets you allocate this much address space, as
long as you don't try to use all of it (this is memory
overcommitment). Running this example on a Linux system with 128Gb of
memory produces

 Error: cannot allocate vector of size 643.7 Gb

I suspect this will fail on pretty much any Windows system as well.

My recommendation would be to figure out a lower upper bound on the
number of elements to read, maybe using file.size, and use that for 'n'
in your readBin call. That will allow your code to be more portable
and avoid the risks of removing the allocation protection.

Best,

luke

On Tue, 12 Jun 2018, Valerie Cavett wrote:


Thanks so much for taking a look at this.


Before setting a new value, I opened a fresh session of R and checked to see 
whether there was any value set for R_MAX_VSIZE. There was not, so we'll assume 
the default as you described.


Next, I tried to set a value with
Sys.setenv("R_MAX_VSIZE" = 8e9)


When the system environment is checked again, there is now a value of

??   R_MAX_SIZE                          8e+09



Unfortunately, when I try to read in a small binary file, I still encounter the 
same error.

??


I restored R 3.3 and checked the system environment to confirm that there was 
no R_MAX_SIZE configured in the startup file, then tested readBin as follows:


    hertz <- 6000
    bin.read = file("20180611_A4", "rb")
    datavals = readBin(bin.read, integer(), size = 2, n = 8*hertz*60*6, endian = 
"little")


datavals is a large integer with 6046880 elements, 23.1 Mb.


If I then set the R_MAX_SIZE to 8e9, this also works just fine since the file 
is not really that large.


However, if I switch back to the newest R version (3.5.0), I encounter the same 
error:


    > datavals = readBin(bin.read, integer(), size = 2, n = 8*hertz*60*6, endian 
= "little")
    Error: vector memory exhausted (limit reached?)


I’m at a loss for why this is an issue (same machine) in R 3.5.0, but not in 
3.3.2 or 3.4.4. If you have any further suggestions, I’d greatly appreciate 
them.


From: luke-tier...@uiowa.edu 
Sent: Tuesday, June 12, 2018 5:26:37 AM
To: Valerie Cavett
Cc: r-help@R-project.org
Subject: Re: [R] R 3.5.0, vector memory exhausted error on readBin


??

This item in NEWS explains the change:

 • The environment variable R_MAX_VSIZE can now be used to specify
   the maximal vector heap size. On macOS, unless specified by this
   environment variable, the maximal vector heap size is set to the
   maximum of 16GB and the available physical memory. This is to
   avoid having the R process killed when macOS over-commits memory.

You can set R_MAX_VSIZE to a larger value but you should do some
experimenting to decide on a safe value for your system. Mac OS is
quite good at using virtual memory up to a point but then gets very
bad. For my 4 GB mac numeric(8e9) works but numeric(9e9) causes R to
be killed, so a setting of around 60GB _might_ be safe.

File size probably doesn't matter in your example since you are
setting a large value for n - I can't tell how large since you didn't
provide your value of 'hertz'.

Best,

luke

On Mon, 11 Jun 2018, Valerie Cavett wrote:


I???ve been reading in binary data collected via LabView for a pr

Re: [R] R 3.5.0, vector memory exhausted error on readBin

2018-06-12 Thread luke-tierney

The environment variable R_MAX_VSIZE is read at start-up so need to be
set outside R. If you are starting R from a shell you can use

env R_MAX_VSIZE=700Gb R

If you use a GUI you might need to set the variable in another
way.

Here is a reproducible version of your example:

hertz <- 6000
binfile <- tempfile()
writeBin(1L, binfile, size = 2)
v <- readBin(binfile, integer(), size = 2, n = 8*hertz*60*6)
unlink(binfile)

With the limit raised to 700Gb or more this will work in R 3.5.0
but you lose the protection of the lower default setting. You need a
value that high because your 'n' value is asking readBin to allocate a
buffer 643.7 Gb. Mac OS lets you allocate this much address space, as
long as you don't try to use all of it (this is memory
overcommitment). Running this example on a Linux system with 128Gb of
memory produces

Error: cannot allocate vector of size 643.7 Gb

I suspect this will fail on pretty much any Windows system as well.

My recommendation would be to figure out a lower upper bound on the
number of elements to read, maybe using file.size, and use that for 'n'
in your readBin call. That will allow your code to be more portable
and avoid the risks of removing the allocation protection.

Best,

luke

On Tue, 12 Jun 2018, Valerie Cavett wrote:


Thanks so much for taking a look at this.


Before setting a new value, I opened a fresh session of R and checked to see 
whether there was any value set for R_MAX_VSIZE. There was not, so we'll assume 
the default as you described.


Next, I tried to set a value with
Sys.setenv("R_MAX_VSIZE" = 8e9)


When the system environment is checked again, there is now a value of

??  R_MAX_SIZE                          8e+09



Unfortunately, when I try to read in a small binary file, I still encounter the 
same error.

??


I restored R 3.3 and checked the system environment to confirm that there was 
no R_MAX_SIZE configured in the startup file, then tested readBin as follows:


hertz <- 6000
bin.read = file("20180611_A4", "rb")
datavals = readBin(bin.read, integer(), size = 2, n = 8*hertz*60*6, endian = 
"little")


datavals is a large integer with 6046880 elements, 23.1 Mb.


If I then set the R_MAX_SIZE to 8e9, this also works just fine since the file 
is not really that large.


However, if I switch back to the newest R version (3.5.0), I encounter the same 
error:


> datavals = readBin(bin.read, integer(), size = 2, n = 8*hertz*60*6, endian 
= "little")
Error: vector memory exhausted (limit reached?)


I’m at a loss for why this is an issue (same machine) in R 3.5.0, but not in 
3.3.2 or 3.4.4. If you have any further suggestions, I’d greatly appreciate 
them.


From: luke-tier...@uiowa.edu 
Sent: Tuesday, June 12, 2018 5:26:37 AM
To: Valerie Cavett
Cc: r-help@R-project.org
Subject: Re: [R] R 3.5.0, vector memory exhausted error on readBin


??

This item in NEWS explains the change:

 • The environment variable R_MAX_VSIZE can now be used to specify
   the maximal vector heap size. On macOS, unless specified by this
   environment variable, the maximal vector heap size is set to the
   maximum of 16GB and the available physical memory. This is to
   avoid having the R process killed when macOS over-commits memory.

You can set R_MAX_VSIZE to a larger value but you should do some
experimenting to decide on a safe value for your system. Mac OS is
quite good at using virtual memory up to a point but then gets very
bad. For my 4 GB mac numeric(8e9) works but numeric(9e9) causes R to
be killed, so a setting of around 60GB _might_ be safe.

File size probably doesn't matter in your example since you are
setting a large value for n - I can't tell how large since you didn't
provide your value of 'hertz'.

Best,

luke

On Mon, 11 Jun 2018, Valerie Cavett wrote:


I???ve been reading in binary data collected via LabView for a project, and 
after upgrading to R 3.5.0, the code returns an error indicating that the 
'vector memory is exhausted???.  I???m happy to provide a sample binary file; 
even ones that are quite small  (12 MB) generate this error. (I wasn???t sure 
whether a binary file attached to this email would trigger a spam filter.)

bin.read = file(files[i], "rb???)
datavals = readBin(bin.read, integer(), size = 2, n = 8*hertz*60*6, endian = 
"little???)

Error: vector memory exhausted (limit reached?)


sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6


This does not happen in R 3.4 (R version 3.4.4 (2018-03-15) -- "Someone to Lean 
On???) - the vector is created and populated by the binary file values without 
issue, even at a 1GB binary file size.

Other files that are read in as csv files, even at 1GB, load correctly to 3.5, 
so I assume that this is a function of a vector being

Re: [R] R 3.5.0, vector memory exhausted error on readBin

2018-06-12 Thread luke-tierney

This item in NEWS explains the change:

• The environment variable R_MAX_VSIZE can now be used to specify
  the maximal vector heap size. On macOS, unless specified by this
  environment variable, the maximal vector heap size is set to the
  maximum of 16GB and the available physical memory. This is to
  avoid having the R process killed when macOS over-commits memory.

You can set R_MAX_VSIZE to a larger value but you should do some
experimenting to decide on a safe value for your system. Mac OS is
quite good at using virtual memory up to a point but then gets very
bad. For my 4 GB mac numeric(8e9) works but numeric(9e9) causes R to
be killed, so a setting of around 60GB _might_ be safe.

File size probably doesn't matter in your example since you are
setting a large value for n - I can't tell how large since you didn't
provide your value of 'hertz'.

Best,

luke

On Mon, 11 Jun 2018, Valerie Cavett wrote:


I???ve been reading in binary data collected via LabView for a project, and 
after upgrading to R 3.5.0, the code returns an error indicating that the 
'vector memory is exhausted???.  I???m happy to provide a sample binary file; 
even ones that are quite small (12 MB) generate this error. (I wasn???t sure 
whether a binary file attached to this email would trigger a spam filter.)

bin.read = file(files[i], "rb???)
datavals = readBin(bin.read, integer(), size = 2, n = 8*hertz*60*6, endian = 
"little???)

Error: vector memory exhausted (limit reached?)


sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6


This does not happen in R 3.4 (R version 3.4.4 (2018-03-15) -- "Someone to Lean 
On???) - the vector is created and populated by the binary file values without 
issue, even at a 1GB binary file size.

Other files that are read in as csv files, even at 1GB, load correctly to 3.5, 
so I assume that this is a function of a vector being explicitly 
defined/changed in some way from 3.4 to 3.5.

Any help, suggestions or workarounds are greatly appreciated!
Val

[[alternative HTML version deleted]]




--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 geterrmessage()

2018-02-22 Thread luke-tierney

Only the default error handler puts the error message in a buffer
where it can be retrieved with geterrmessage. try() replaces the
default error handler. Either look at the value returned by try() or
use tryCatch with conditionMessage.

Best,

luke

On Thu, 22 Feb 2018, Dennis Fisher wrote:


R 3.4.3
OS X

Colleagues

I have a 20K line script in which I encounter an unexpected problem.

If the script detects presence of a particular file USERCODE.txt, it executes:
source(“USERCODE.txt”)
If that file is not present, the script executes without a problem.

There might be syntax errors in USERCODE.txt; therefore, the code above is 
embedded in a try command:
try(source(“USERCODE.txt", local=T), silent=T)
followed by:
ERRORMESSAGE <- geterrmessage()

For unclear reasons, an earlier command is yielding an error message:
unused argument (\"\\n\")
Despite identifying the exact source of that error, I can’t fix it (and it is 
of no consequence).

Ideally, I would like to clear out the pre-existing error message immediately 
before the “try” command (or perhaps at that particular location where it is 
being created) — but I can’t figure out how to do so.

Any suggestions would be welcome.

Dennis

Dennis Fisher MD
P < (The "P Less Than" Company)
Phone / Fax: 1-866-PLessThan (1-866-753-7784)
www.PLessThan.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.



--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Chi2 algorithm - R

2016-11-23 Thread Luke Skywalker
What does it mean to "have a mantainer"? Is he a third party? Is he an
individual developer and you can install whose package on your risk? Are
the package created by maintainers not tested?

Anyway, I wrote him. I'm waiting for response.

Regards

Il 23/Nov/2016 22:21, "peter dalgaard" <pda...@gmail.com> ha scritto:

> Notice that this relates to an R _package_, which has a maintainer. You
> cannot expect general R users or developers to know about the details of
> the package. It doesn't look like there is dcoumentation beyond the help
> pages, so you may need to contact the maintainer or study the actual code.
>
> -pd
>
> > On 23 Nov 2016, at 17:08 , Luke Skywalker <mattere...@gmail.com> wrote:
> >
> > Good evening,
> >
> > I'm encountering a different kind of discretization with respect to the
> > 1997 Liu and Setiono's one descripted in their papers, using Chi2
> algorithm
> > for feature selection with discretization.
> >
> > As stated in R documentation (discretization - R (from CRAN)
> > <https://cran.r-project.org/web/packages/discretization/
> discretization.pdf>),
> > R package discretizion offers the function Chi2, which comes to life in
> the
> > following papers:
> >
> > Liu, H. and Setiono, R. (1995). Chi2: Feature selection and
> discretization
> > of numeric attributes, Tools with Artificial Intelligence, 388–391.
> >
> > Liu, H. and Setiono, R. (1997). Feature selection and discretization,
> IEEE
> > transactions on knowledge and data engineering, Vol.9, no.4, 642–645.
> >
> > I wrote the following R programming language code, in which I have set
> > alpha and delta equal to the ones set in the papers above. Finally, the
> > following code prints out the discretized dataframe. I used Iris
> dataframe,
> > as in one of the examples in the two papers. The first paper above states
> > that alfa = 0.5 and delta = 5%, and that "the originally odd numbered
> data
> > are selected for training (75 patterns) and rest for testing (75
> > patterns)". With this asset, Sepal attributes should be removed.
> >
> > library(discretization)
> > data(iris)
> > df1 <- iris[FALSE,]for(i in 1:nrow(iris)){
> >if(i %% 2 != 0){
> >df1 <- rbind(df1, iris[i,])
> >}}
> > chi2(df1, alp=0.5, del=0.05)$Disc.data
> >
> > The point is that, observing the dataframe printed out by the last
> > instruction, you can see that no attribute is removed. The discretized
> data
> > frame still have 4 attributes discretized: if I correctly understood the
> > above papers, Sepal Length and Sepal Width should have been both
> > discretized in just one interval by Chi2 algorithm.
> >
> > I have posted a question here: http://stats.stackexchange.com/questions/
> > 247499/why-does-not-r-chi2-algorithm-discretize-in-the-
> > same-manner-as-in-the-paper-by-l?noredirect=1#comment470974_247499.
> >
> >
> > Moreover, it's really hard to understand the cut points that Chi2
> algorithm
> > implemented in R makes. For example:
> >
> > res <- chi2(iris, 0.5, 0.05)
> >
> > cut(iris$Sepal.Length, res$cutp, labels=FALSE) is different from
> > res$Disc.data$Sepal.Length
> >
> > Help me understand, please
> >
> > Best regards
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>
>
>
>
>
>
>
>
>

[[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] Chi2 algorithm - R

2016-11-23 Thread Luke Skywalker
Good evening,

I'm encountering a different kind of discretization with respect to the
1997 Liu and Setiono's one descripted in their papers, using Chi2 algorithm
for feature selection with discretization.

As stated in R documentation (discretization - R (from CRAN)
),
R package discretizion offers the function Chi2, which comes to life in the
following papers:

Liu, H. and Setiono, R. (1995). Chi2: Feature selection and discretization
of numeric attributes, Tools with Artificial Intelligence, 388–391.

Liu, H. and Setiono, R. (1997). Feature selection and discretization, IEEE
transactions on knowledge and data engineering, Vol.9, no.4, 642–645.

I wrote the following R programming language code, in which I have set
alpha and delta equal to the ones set in the papers above. Finally, the
following code prints out the discretized dataframe. I used Iris dataframe,
as in one of the examples in the two papers. The first paper above states
that alfa = 0.5 and delta = 5%, and that "the originally odd numbered data
are selected for training (75 patterns) and rest for testing (75
patterns)". With this asset, Sepal attributes should be removed.

library(discretization)
data(iris)
df1 <- iris[FALSE,]for(i in 1:nrow(iris)){
if(i %% 2 != 0){
df1 <- rbind(df1, iris[i,])
}}
chi2(df1, alp=0.5, del=0.05)$Disc.data

The point is that, observing the dataframe printed out by the last
instruction, you can see that no attribute is removed. The discretized data
frame still have 4 attributes discretized: if I correctly understood the
above papers, Sepal Length and Sepal Width should have been both
discretized in just one interval by Chi2 algorithm.

I have posted a question here: http://stats.stackexchange.com/questions/
247499/why-does-not-r-chi2-algorithm-discretize-in-the-
same-manner-as-in-the-paper-by-l?noredirect=1#comment470974_247499.


Moreover, it's really hard to understand the cut points that Chi2 algorithm
implemented in R makes. For example:

res <- chi2(iris, 0.5, 0.05)

cut(iris$Sepal.Length, res$cutp, labels=FALSE) is different from
res$Disc.data$Sepal.Length

Help me understand, please

Best regards

[[alternative HTML version deleted]]

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

[R] Permutations in matched-pair study where combinations of pairs change

2016-10-31 Thread Luke Gaylor
Friends,


Matched pairs studies are well documented, but what happens if we were to alter 
the manner in which events were paired to one another. Say we change the order 
of our data and pair without replacement, so that event 1 may pair with event 
23 in one instance, but also event 36 or 102 in other instances.

Matched pair study can then be used to determine the effectiveness of, for 
example a treatment program, on a given outcome. The outcome may be continuous 
or variable. Therefore, a conditional logistic regression model can output an 
odds ratio (and confidence intervals for the treatment coefficient). Or we may 
use a paired t-test to assess if the difference in means between the pairs 
differ.

I am more favored to the logistic regression and output of the odds ratio, 
however it changes for each permutation. As too does its confidence interval. 
So my question is how can we report on a string of given odds ratios - how can 
be arrive at a statistical sound conclusion? Or accounting for the study 
design, where we achieve different combinations of matched pairs, how can be 
comment on the effectiveness of a given treatment program?

Below I have attached a code, which simulates a 100-fold permutation.


Any advice would be greatly appreciated,
Luke


Set.seed(123)
# prepare the data for the simulation
#1.
library(Matching)
library(survival)
library(dplyr)
#2.
require(doParallel)
cl<-makeCluster(2)
registerDoParallel(cl)
#3.
clusterEvalQ(cl,library(Matching))
clusterEvalQ(cl,library(survival))
clusterEvalQ(cl,library(dplyr))

# number of permutations
m <- 100


Result = foreach(i=1:m,.combine=cbind) %do%{

  # taking from the example from the Matching package
  #attach the data
  data(lalonde)

  # we want to assess if treatment shows an influence on a given outcome of 
interest
  # lets create our hypothetical example
  lalonde$success <- with(lalonde, ifelse(re78 > 8125, 1, 0))

  # adjust the order of the data
  lalonde <- lalonde[sample(1:nrow(lalonde)), ]
  head(lalonde$age)


  # Define the covariates we want to match on
  Xmat = cbind(lalonde$age, lalonde$educ, lalonde$married, lalonde$nodegr)

  # define crude matching
  mgen1 <- Match(Y=NULL, Tr=lalonde$treat,
 X=Xmat,
 exact=c(0,1,1,1),
 replace=FALSE, ties=F)

  summary(mgen1)

  # obtain initial pair-combinations
  matched <- rbind(lalonde[mgen1$index.treated,], lalonde[mgen1$index.control,])

  # generate a dummy variable for our each pair of people
  matched$Pair_ID <- rep(1:length(mgen1$index.treated),2)

  # crude filtering
  # set hard limits of age
  # must be within +-2 years
  Matched2 <- matched %>%
group_by(Pair_ID) %>%
filter(abs( age[treat == 1] - age[treat == 0]) <= 2)

  # summary table
  table(Matched2$treat, Matched2$success)

  # so now we have a cohort of similar events
  # each pair contains one treat and one non-treat event


  ###
  # #
  # H E R E   W E   A R E   T R Y I N GT O  #
  #  A S S E S S   T H EE F F E C T I V E N E S S   #
  #   O F   T R E A T M E N T   T OA C H I E V E#
  #   s U C C E S S #
  # #
  ###


  # One could implement a parametric difference of means test
  # t-test - (as the outcome of interest is binary)
  # to assess if differences between pairs change

  diff_means<- t.test(Matched2$success[Matched2$treat==1], 
Matched2$success[Matched2$treat==0],
 paired = T, alternative = "two.sided", conf.level = 0.95)
  diff_means$p.value

  # output the series of p-values for each permutation

  # ===
  # Or
  # ===

  # obtain an estimated effectiveness value from a conditional logistic 
regression
  # namely, the Odds Ratio coefficient for 'treat'
  model_1 <- clogit(success ~ treat + strata(Pair_ID), matched)
  summary(model_1)

  OR_M1 <- exp(model_1$coefficients[1])

  # we can save the confidence intervals for the 'treat' effectiveness
  CI_U1 <- exp(confint(model_1))[1,2]
  CI_L1 <- exp(confint(model_1))[1,1]

  # then we could output any of the following
  #Result <- diff_means$p.value
  #Result <- OR_M1
  #Result <- rbind(OR_M1, CI_U1, CI_L1)

  Result <- OR_M1

}

summary(Result[1,])




[[alternative HTML version deleted]]

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


Re: [R] Memory not release when an environment is created

2016-09-22 Thread luke-tierney

On Thu, 22 Sep 2016, luke-tier...@uiowa.edu wrote:


My preference is to use a top level function in the package or global
env that takes as arguments just the variables I want in the parent
frame. That avoids the explicit environment manipulations. Here that
would be


makeFunc0 <- function(xmin, xmax)

 function(y) (y - xmin) / (xmax - xmin)



But I do keep forgetting the need to force the parameters if you don't
want a big value to stick around until the returned function is used
the first time, so a better definition of makeFUnc0 is

makeFunc0 <- function(xmin, xmax) {
force(xmin)
force(xmax)
function(y) (y - xmin) / (xmax - xmin)
}

Best,

luke


makeFunc1 <- function(x)

 makeFunc0(min(x), max(x))


f <- makeFunc1(1:1e8)
ls.str(all=TRUE, environment(f))

xmax :  int 1
xmin :  int 1

parent.env(environment(f))



f(c(1234567, 2345678))

[1] 0.01234566 0.02345677

Best,

luke


On Thu, 22 Sep 2016, William Dunlap via R-help wrote:


I like to have my function-returning functions use new.env(parent=XXX)
to make an environment for the returned function and put into it only
the objects needed by the function.  The 'XXX' should be a an environment
which will hang around anyway.  It could be globalenv(), but if your
function
is in a package, as.environment(paste0("package:", .packageName))
would work well.  The later ensures the your returned function has access
to all the other functions in that package.

E.g.,

makeFunc1 <- function(x) {

   envir <- new.env(parent = environment(sys.function()))
   envir$xmax <- max(x)
   envir$xmin <- min(x)
   with(envir, function(y) (y - xmin) / (xmax - xmin))
}

f <- makeFunc1(1:1e8)
ls.str(all=TRUE, environment(f))

xmax :  int 1
xmin :  int 1

parent.env(environment(f))



f(c(1234567, 2345678))

[1] 0.01234566 0.02345677



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Sep 22, 2016 at 8:41 AM, Olivier Merle <oliviermerl...@gmail.com>
wrote:


Dear,

When I use big data for a temporary use it seems that the memory is not
released when a function/environement is created nearby.
Here the reproducible exemple:

test<-function(){
x=matrix(0,5,1)
y=function(nb) nb^2
return(y)
}
xx=test() # 3 Go of Ram is used
gc() # Memory is not released !! even if x has been destroyed [look into
software mem used]
format(object.size(xx),units="auto") # 1.4 KiB => R is worng on the size
of
the object
rm(xx)
gc() # Memory is released

## Classic
test2<-function(){
x=matrix(0,5,1)
y=1
return(y)
}
xx=test2() # Memory is used
gc() # => Memory is released

How can I release the data in test without destroying the xx object ? As x
which is big object is destroyed, I though I could get my memory back but
it seems that the function y is keeping the x object.

Best

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






--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Memory not release when an environment is created

2016-09-22 Thread luke-tierney

My preference is to use a top level function in the package or global
env that takes as arguments just the variables I want in the parent
frame. That avoids the explicit environment manipulations. Here that
would be


makeFunc0 <- function(xmin, xmax)

  function(y) (y - xmin) / (xmax - xmin)


makeFunc1 <- function(x)

  makeFunc0(min(x), max(x))


f <- makeFunc1(1:1e8)
ls.str(all=TRUE, environment(f))

xmax :  int 1
xmin :  int 1

parent.env(environment(f))



f(c(1234567, 2345678))

[1] 0.01234566 0.02345677

Best,

luke


On Thu, 22 Sep 2016, William Dunlap via R-help wrote:


I like to have my function-returning functions use new.env(parent=XXX)
to make an environment for the returned function and put into it only
the objects needed by the function.  The 'XXX' should be a an environment
which will hang around anyway.  It could be globalenv(), but if your
function
is in a package, as.environment(paste0("package:", .packageName))
would work well.  The later ensures the your returned function has access
to all the other functions in that package.

E.g.,

makeFunc1 <- function(x) {

   envir <- new.env(parent = environment(sys.function()))
   envir$xmax <- max(x)
   envir$xmin <- min(x)
   with(envir, function(y) (y - xmin) / (xmax - xmin))
}

f <- makeFunc1(1:1e8)
ls.str(all=TRUE, environment(f))

xmax :  int 1
xmin :  int 1

parent.env(environment(f))



f(c(1234567, 2345678))

[1] 0.01234566 0.02345677



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Sep 22, 2016 at 8:41 AM, Olivier Merle <oliviermerl...@gmail.com>
wrote:


Dear,

When I use big data for a temporary use it seems that the memory is not
released when a function/environement is created nearby.
Here the reproducible exemple:

test<-function(){
x=matrix(0,5,1)
y=function(nb) nb^2
return(y)
}
xx=test() # 3 Go of Ram is used
gc() # Memory is not released !! even if x has been destroyed [look into
software mem used]
format(object.size(xx),units="auto") # 1.4 KiB => R is worng on the size
of
the object
rm(xx)
gc() # Memory is released

## Classic
test2<-function(){
x=matrix(0,5,1)
y=1
return(y)
}
xx=test2() # Memory is used
gc() # => Memory is released

How can I release the data in test without destroying the xx object ? As x
which is big object is destroyed, I though I could get my memory back but
it seems that the function y is keeping the x object.

Best

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



--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] interaction between clusterMap(), read.csv() and try() - try does not catch error

2016-08-08 Thread luke-tierney

try is working fine. The problem is that your remote function is
returning the try-error result, which the parallel infrastructure is
interpreting as an error on the remote node, since the remote calling
infrastructure is using try as well. This could be implemented more
robustly, but it would probably be better in any case your code to use
can use tryCatch and have the error. function return something easier
to work with, like NULL.

Best,

luke

On Mon, 8 Aug 2016, Strunk, Jacob (DNR) wrote:


Hello I am attempting to process a list of csv files in parallel, some of which 
may be empty and fail with read.csv. I tend to use clusterMap as my go-to 
parallel function but have run into an interesting behavior. The behavior is 
that try(read.csv(x)) does not catch read errors resulting from having an empty 
csv file inside of clusterMap. I have not tested this with other functions 
(e.g. read.table, mean, etc.). The parLapply function does, it appears, 
correctly catch the errors. Any suggestions on how I should code with 
clusterMap such that try is guaranteed to catch the error?


I am working on windows server 2012
I have the latest version of R and parallel
I am executing the code from within the rstudio ide Version 0.99.896

Here is a demonstration of the failure

R code used in demonstration:
#prepare csv files - an empty file and a file with data
close(file("c:/temp/badcsv.csv",open="w"))
write.table(data.frame(x=2),"c:/temp/goodcsv.csv")

#prepare a parallel cluster
clus0=makeCluster(1, rscript_args = "--no-site-file")

#read good / bad files in parallel with parLapply - which succeeds: try Does 
catch err
x1=parLapply(clus0,c("c:/temp/badcsv.csv","c:/temp/goodcsv.csv"),function(...)try(read.csv(...)))
print(x1)

#read good / bad files in parallel with clusterMap - which fails: try does Not 
catch error
x0=clusterMap(clus0,function(...)try(read.csv(...)),c("c:/temp/badcsv.csv","c:/temp/goodcsv.csv"),SIMPLIFY=F)
print(x0)

R output:


#prepare csv files - an empty file and a file with data
close(file("c:/temp/badcsv.csv",open="w"))
write.table(data.frame(x=2),"c:/temp/goodcsv.csv")

#prepare a parallel cluster
clus0=makeCluster(1, rscript_args = "--no-site-file")

#read good / bad files in parallel with parLapply - which succeeds: try Does 
catch err
x1=parLapply(clus0,c("c:/temp/badcsv.csv","c:/temp/goodcsv.csv"),function(...)try(read.csv(...)))
print(x1)

[[1]]
[1] "Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
\n  no lines available in input\n"
attr(,"class")
[1] "try-error"
attr(,"condition")


[[2]]
   x
1 1 2



#read good / bad files in parallel with clusterMap - which fails: try does Not 
catch error
x0=clusterMap(clus0,function(...)try(read.csv(...)),c("c:/temp/badcsv.csv","c:/temp/goodcsv.csv"),SIMPLIFY=F)

Error in checkForRemoteErrors(val) :
 one node produced an error: Error in read.table(file = file, header = header, 
sep = sep, quote = quote,  :
 no lines available in input

print(x0)

Error in print(x0) : object 'x0' not found





Thanks for any help,
Jacob


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



--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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: Help: malloc/free deadlock in unsafe signal handler 'Rf_onsigusr1'

2016-08-01 Thread luke-tierney

The handlers for SIGUSR1 and SIGUSR2 are really intended as an
emergency break, not for ordinary programming. These could be
rewritten to be safer but that would make them less immediate.

Followups would be more appropriate on R-devel.

Best,

luke

On Mon, 1 Aug 2016, Ming Li wrote:


Hi all,

I am working on a bug,  which running PLR on HAWQ. The process hung and
can't be terminated.


From my investigation, it seems signal handler 'Rf_onsigusr1' trigger a

malloc/free deadlock.

The calling stack is below.

Thread 1 (Thread 0x7f4c93af48e0 (LWP 431263)):
#0  0x7f4c9015805e in __lll_lock_wait_private () from /lib64/libc.so.6
#1  0x7f4c900dd16b in _L_lock_9503 () from /lib64/libc.so.6
#2  0x7f4c900da6a6 in malloc () from /lib64/libc.so.6
#3  0x7f4c9008fb39 in _nl_make_l10nflist () from /lib64/libc.so.6
#4  0x7f4c9008ddf5 in _nl_find_domain () from /lib64/libc.so.6
#5  0x7f4c9008d6e0 in __dcigettext () from /lib64/libc.so.6
#6  0x7f4c6fabcfe3 in Rf_onsigusr1 () from /usr/local/lib64/R/lib/libR.so
#7  
#8  0x7f4c9014079a in brk () from /lib64/libc.so.6
#9  0x7f4c90140845 in sbrk () from /lib64/libc.so.6
#10 0x7f4c900dd769 in __default_morecore () from /lib64/libc.so.6
#11 0x7f4c900d87a2 in _int_free () from /lib64/libc.so.6
#12 0x00b3ff24 in gp_free2 ()
#13 0x00b356fc in AllocSetDelete ()
#14 0x00b38391 in MemoryContextDeleteImpl ()
#15 0x0077c851 in ExecEndAgg ()
#16 0x007592ad in ExecEndNode ()
#17 0x0075186c in ExecEndPlan ()
#18 0x0079dffa in ExecEndSubqueryScan ()
#19 0x0075921d in ExecEndNode ()
#20 0x0075186c in ExecEndPlan ()
#21 0x00752565 in ExecutorEnd ()
#22 0x006dd9bd in PortalCleanup ()
#23 0x00b3f077 in AtCommit_Portals ()
#24 0x0051abe5 in CommitTransaction ()
#25 0x0051f1d5 in CommitTransactionCommand ()
#26 0x0099809e in PostgresMain ()
#27 0x008f1031 in BackendStartup ()
#28 0x008f70e0 in PostmasterMain ()
#29 0x007f63da in main ()


I googled and found below info maybe useful to fix it: The best way to
avoid this kind of deadlock is to Call only asynchronous-safe functions
within signal handlers.

https://www.securecoding.cert.org/confluence/display/c/SIG30-C.+Call+only+asynchronous-safe+functions+within+signal+handlers

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.



--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] C stack error in as.vector() starting in R 3.3.0

2016-07-06 Thread luke-tierney

I cannot reproduce this.  My best guess is that there is a problem,
maybe a version incompatibility, with one of the packages loaded when
load("problem.method.rdata"). This includes

adegenet
apex
copula
Rcpp
DBI
sp
colorspace

and any dependencies these are bringing in.

Best,

luke

On Fri, 1 Jul 2016, Eric Archer - NOAA Federal wrote:


Apologies for the long post. This is an issue I have been struggling with
and I have tried to be as complete, to the point, and reproducible as
possible.

In documenting a package with roxygen2, I have come across an error that
does not occur in R 3.2.4 revised, but does occur in R 3.3.0 and 3.3.1.
Using traceback() and debug(), I've traced the error to a call made to
as.vector(x, "character") that seems to get stuck in a loop which
culminates in this error:

Error: C stack usage  7970892 is too close to the limit

The object that causes this error is of a signature type for a method. With
some playing around, I've been able to work out that the error is actually
associated with the method that roxygen2 creates when doing its magic.
Something happens when this method definition with its associated
environment is in the workspace that causes the error.

At this point, I should stress again that the error does NOT occur in R
3.2.4 revised or earlier, but does occur in R 3.3.0 and 3.3.1. I have also
tested this with several versions of roxygen2 and that does not make a
difference. Thus, my ultimate question is what has changed in R 3.3.0 that
would lead to this so that the roxygen2 maintainers can correct it?

As a test, I created a signature identical to the one that causes the error
and tried the as.vector() command that would generate the loop. I don't get
the error in my command line generated object, nor with the object that is
extracted from the method definition. However, when I load the method
definition into the workspace, the error will happen on either my command
line generated object, or the one extracted from the method definition and
will not stop happening until I restart R.

I have reported this error as an issue on the roxygen2 GitHub repository
and it has been crossposted by another user who had a similar experience
with a different package on the devtools repository. Those posts, which
contain more information are here:

https://github.com/klutometis/roxygen/issues/475
https://github.com/hadley/devtools/issues/1234

Below is the result of sessionInfo() and the output of a session
demonstrating the effect. The files used are in a zip file here:
https://github.com/klutometis/roxygen/files/335417/error.test.rdata.files.zip

> sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.5 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

loaded via a namespace (and not attached):
[1] tools_3.3.0


rm(list = ls())

# Create test class and method
setClass(Class = "gtypes", slots = c(loci = "data.frame", ploidy =

"numeric"), package = "roxygen_devtest")

setGeneric("nInd", function(x, ...) standardGeneric("nInd"), package =

"adegenet")
[1] "nInd"

setMethod("nInd", "gtypes", function(x, ...) nrow(x@loci) / x@ploidy)

[1] "nInd"


test.method <- getMethod("nInd", "gtypes")
str(test.method)

Formal class 'MethodDefinition' [package "methods"] with 4 slots
 ..@ .Data  :function (x, ...)
 ..@ target :Formal class 'signature' [package "methods"] with 3 slots
 .. .. ..@ .Data  : chr "gtypes"
 .. .. ..@ names  : chr "x"
 .. .. ..@ package: chr "roxygen_devtest"
 ..@ defined:Formal class 'signature' [package "methods"] with 3 slots
 .. .. ..@ .Data  : chr "gtypes"
 .. .. ..@ names  : chr "x"
 .. .. ..@ package: chr "roxygen_devtest"
 ..@ generic: atomic [1:1] nInd
 .. ..- attr(*, "package")= chr "adegenet"


# No error:
as.vector(test.method@defined, "character")

[1] "gtypes"


# This is the method that generates the error
load("problem.method.rdata")

# Notice the difference in the environments of the two functions:
test.method@.Data

function (x, ...)
nrow(x@loci)/x@ploidy

problem.method@.Data

function (x, ...)
nrow(x@loci)/x@ploidy



# Swap the problem function for the one I created:
problem.method@.Data <- test.method@.Data
save(problem.method, file = "fixed.method.rdata")

# Here's the error (both with my method and the original):
as.vector(test.method@defined, "character")

Error: C stack usage  7970892 is too close to the limit

as.vector(problem.method@defined, "character")

Error: C stack usage  7970892 is too close to the limit

Restarting R ses

[R] post a message - R help. Surivival analysis and goodness of fit

2015-11-05 Thread Luke Gaylor
Hello there,

I have registered for both through nabble and R-help-request with this email.

I want to post the following question:

I want to implement a Hosmer Lemeshow Goodness of Fit test to my survival 
analysis.
In R we can use the hoslem.test() function.
The x values are our observations, and y are our fitted probabilities.

So we can take the following data:

s <- Surv(ovarian$futime, ovarian$fustat)
sWei <- survreg(s ~ age,dist='weibull',data=ovarian)

so here we assume a weibull distribution. I want to do a HL GOF test to see, if 
this is an invalid assumption.
Now how do we get our predicted probabilities. I assume it is with the 
predict() function.
I have tried the code, but it is not correct

predict(sWei, newdata=list(ovarian$age), type = 'response')
  
[[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] Rscript silent failures with unmatched brackets

2015-02-26 Thread Luke Moryl
Hi all,

I’ve noticed that a script with unmatched brackets of any sort will fail
silently in Rscript—neither logging nor any output in the shell indicates
that anything went wrong. Example file to run in Rscript:

sink('/tmp/exampleoutfile')
a - 0
{
  print(a)

Replacing the ‘{‘ with any other symbol that must be matched (quotes,
parens, etc.) results in the same kind of silent failure. One workaround is
to use

echo source('myscript.R') | R --no-save --no-restore

from the command line but that’s a kludge. My apologies if this has been
brought up before, but doing a quick search I didn’t find anything, and to
me this seems like a significant bug.

Thanks  best,
Luke
​

[[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] snow/Rmpi without MPI.spawn?

2014-09-04 Thread luke-tierney

You could look into the RMPISNOW shell script that is included in snow
for use with mpirun, eg as

mpirun -np 3 RMPISNOW

The script might need adjusting for your setting.

Best,

luke

On Thu, 4 Sep 2014, Jim Leek wrote:

Ah, now it's working.  Thanks.  Now I just need to figure out how to get snow 
doing this...


Jim

On 09/04/2014 05:03 AM, Martin Morgan wrote:

On 09/03/2014 10:24 PM, Leek, Jim wrote:
Thanks for the tips.  I'll take a look around for for loops in the 
morning.


I think the example you provided worked for OpenMPI.  (The default on our 
machine is MPICH2, but it gave the same error about calling spawn.) 
Anyway, with OpenMPI I got this:



# salloc -n 12 orterun -n 1 R -f spawn.R
library(Rmpi)
## Recent Rmpi bug -- should be mpi.universe.size() nWorkers - 
mpi.universe.size()


(the '## Recent Rmpi bug' comment should have been removed, it's a holdover 
from when the script was written several years ago)



nslaves = 4
mpi.spawn.Rslaves(nslaves)


The argument needs to be named

  mpi.spawn.Rslaves(nslaves=4)

otherwise R matches unnamed arguments by position, and '4' is associated 
with the 'Rscript' argument.


Martin


Reported: 2 (out of 2) daemons - 4 (out of 4) procs

Then it hung there.  So things spawned anyway, which is progress.  I'm 
just not sure is that expected behavior for parSupply or not.


Jim

-Original Message-
From: Martin Morgan [mailto:mtmor...@fhcrc.org]
Sent: Wednesday, September 03, 2014 5:08 PM
To: Leek, Jim; r-help@r-project.org
Subject: Re: [R] snow/Rmpi without MPI.spawn?

On 09/03/2014 03:25 PM, Jim Leek wrote:

I'm a programmer at a high-performance computing center.  I'm not very
familiar with R, but I have used MPI from C, C++, and Python. I have
to run an R code provided by a guy who knows R, but not MPI. So, this
fellow used the R snow library to parallelize his R code
(theoretically, I'm not actually sure what he did.)  I need to get
this code running on our machines.

However, Rmpi and snow seem to require mpi spawn, which our computing
center doesn't support.  I even tried building Rmpi with MPICH1
instead of 2, because Rmpi has that option, but it still tries to use 
spawn.


I can launch plenty of processes, but I have to launch them all at
once at the beginning. Is there any way to convince Rmpi to just use
those processes rather than trying to spawn its own?  I haven't found
any documentation on this issue, although I would've thought it would be 
quite common.


This script

spawn.R
===
# salloc -n 12 orterun -n 1 R -f spawn.R
library(Rmpi)
## Recent Rmpi bug -- should be mpi.universe.size() nWorkers - 
mpi.universe.size()

mpi.spawn.Rslaves(nslaves=nWorkers)
mpiRank - function(i)
c(i=i, rank=mpi.comm.rank())
mpi.parSapply(seq_len(2*nWorkers), mpiRank)
mpi.close.Rslaves()
mpi.quit()

can be run like the comment suggests

 salloc -n 12 orterun -n 1 R -f spawn.R

uses slurm (or whatever job manager) to allocate resources for 12 tasks 
and spawn within that allocation. Maybe that's 'good enough' -- spawning 
within the assigned allocation? Likely this requires minimal modification 
of the current code.


More extensive is to revise the manager/worker-style code to something 
more like single instruction, multiple data



simd.R
==
## salloc -n 4 orterun R --slave -f simd.R
sink(/dev/null) # don't capture output -- more care needed here
library(Rmpi)

TAGS = list(FROM_WORKER=1L)
.comm = 0L

## shared `work', here just determine rank and host
work = c(rank=mpi.comm.rank(.comm),
   host=system(hostname, intern=TRUE))

if (mpi.comm.rank(.comm) == 0) {
  ## manager
  mpi.barrier(.comm)
  nWorkers = mpi.comm.size(.comm)
  res = list(nWorkers)
  for (i in seq_len(nWorkers - 1L)) {
  res[[i]] - mpi.recv.Robj(mpi.any.source(), TAGS$FROM_WORKER,
comm=.comm)
  }
  res[[nWorkers]] = work
  sink() # start capturing output
  print(do.call(rbind, res))
} else {
  ## worker
  mpi.barrier(.comm)
  mpi.send.Robj(work, 0L, TAGS$FROM_WORKER, comm=.comm)
}
mpi.quit()

but this likely requires some serious code revision; if going this route 
then

http://r-pbd.org/ might be helpful (and from a similar HPC environment).

It's always worth asking whether the code is written to be efficient in R 
-- a

typical 'mistake' is to write R-level explicit 'for' loops that
copy-and-append results, along the lines of

 len - 10
 result - NULL
 for (i in seq_len(len))
 ## some complicated calculation, then...
 result - c(result, sqrt(i))

whereas it's much better to pre-allocate and fill

  result - integer(len)
  for (i in seq_len(len))
  result[[i]] = sqrt(i)

or

  lapply(seq_len(len), sqrt)

and very much better still to 'vectorize'

  result - sqrt(seq_len(len))

(timing for me are about 1 minute for copy-and-append, .2 s for 
pre-allocate

and fill, and .002s for vectorize).

Pushing back

[R] R function returning a list of variable(s) conditional on the value of an option?

2014-07-25 Thread Luke Hartigan
Dear all,

I have an R function which returns a list of variables; however, within the
body of the function I would like to incorporate a branch based on a user
selected option that will mean there will be one different variable to
return based on the option value.

I was thinking of doing something like this (only an example):

foo - function(x, y, option = TRUE)
{
.
If (option == TRUE) {
z = z
} else {
w = w
}
return(list(x = x, y = y, z = ifelse(option == TRUE, z, NA), w =
ifelse(option != TRUE, w, NA))

}

However, I was wondering if anyone else had a better idea/method which might
be more elegant?

Many thanks,
Luke



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] lapply returns NULL ?

2014-07-12 Thread luke-tierney

Another option is

Filter(function(x) x[1] == 1, foo)

Best,

luke
On Sat, 12 Jul 2014, ce wrote:



Thanks Jeff et. all,

This is exactly what I needed.

-Original Message-
From: Jeff Newmiller [jdnew...@dcn.davis.ca.us]
Date: 07/12/2014 10:38 AM
To: Uwe Ligges lig...@statistik.tu-dortmund.de, ce zadi...@excite.com, 
r-help@r-project.org
Subject: Re: [R] lapply returns NULL ?

I think that removing them is something the OP doesn't understand how to do.

The lapply function ALWAYS produces an output element for every input element. 
If this is not what you want then you need to choose a looping structure that 
is not so tightly linked to the input, such as a for loop (untested):

result - list()
for (nm in names(foo)) {
 if ( 1 == foo[[nm]][1] ) {
   result[[ nm ]] - foo[[ nm ]]
 }
}
result

or use vector indexing (lists are a special kind of vector) with the loop 
result:

foo[ sapply(foo,function(v){1==v[1]}) ]

---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
 Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

On July 12, 2014 6:37:44 AM PDT, Uwe Ligges lig...@statistik.tu-dortmund.de 
wrote:



On 12.07.2014 15:25, ce wrote:



Dear all,

I have a list of arrays :

foo-list(A = c(1,3), B =c(1, 2), C = c(3, 1))


foo

$A
[1] 1 3

$B
[1] 1 2

$C
[1] 3 1


if( foo$C[1] == 1 ) foo$C[1]



  lapply(foo, function(x) if(x[1] == 1 )  x  )


$A
[1] 1 3

$B
[1] 1 2

$C
NULL

I don't want to list $C NULL  in the output. How I can do that ?


Either use your own print function or, if you do not want NULL elements

in the object, remove them.

Best,
Uwe Ligges



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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
https://stat.ethz.ch/mailman/listinfo/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
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Default argument not passed to subfunction when argument name matches default expression

2014-03-31 Thread Tierney, Luke
Compiled code gives a better error message (not clear why the
interpreter doesn't do this as well):

 cmpfun(foo)()
Error in bar() :
  promise already under evaluation: recursive default argument reference or ear$

The environment in which default arguments are evaluated is the
environment of the function call itself, not the environment of the
caller or the lexical enclosure (the same here). So the two 'y' used
in function(y = y) refer to the same binding, hence circular
reference. If you use

foo - function (z = 2) {
 bar - function (y = z) y^2
bar()
}

then there is no problem:

 foo()
[1] 4
 cmpfun(foo)()
[1] 4

Best,

luke

Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu



From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] on behalf of 
Philippe Grosjean [phgrosj...@sciviews.org]
Sent: Monday, March 31, 2014 9:40 AM
To: R Help
Subject: [R] Default argument not passed to subfunction when argument name  
matches default expression

Hello,

I have difficulties to understand this one:

foo - function (y = 2) {
bar - function (y = y) y^2
bar()
}
foo()
#! Error in y^2 : 'y' is missing
foo(3)
#! Error in y^2 : 'y' is missing

Note that this one works:

foo - function (y = 2) {
bar - function (y = y) y^2
bar(y) # Not using default value for y= argument
}
foo()
#! [1] 4
foo(3)
#! [1] 9

… as well as this one:

foo - function (y = 2) {
bar - function (Y = y) Y^2
bar() # Default, but different names for argument Y= and value 'y'
 }
foo()
#! [1] 4
foo(3)
#! [1] 9

Best,

PhG

 sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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
https://stat.ethz.ch/mailman/listinfo/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] Performance issue with attributes

2014-03-11 Thread luke-tierney

You can also upgrade to R-devel or to R 3.1.0 due out in a month or so
-- those will run this code much more efficiently.

Using setattr is OK if you really know what you are doing, but if you
are not careful using it can modify objects you do not intend to
modify.

Best,

luke

On Tue, 11 Mar 2014, Smart Guy wrote:


Apologies for the late reply. I was out on vacation.
I tried setattr() from data.table package and it worked like a magic.

Thanks a lot for the help. setattr() is really faster than attributes.

Regards,
SG


On 22 February 2014 12:29, Philippe Grosjean phgrosj...@sciviews.orgwrote:


You can use setattr() in the data.table package. It can be used too on
data.frames or other objects.
Best,

Philippe Grosjean


On 22 Feb 2014, at 03:13, Smart Guy smartgu...@gmail.com wrote:


Hi All

I am having problem running the 'attributes' command to set a attribute

on

each column of a large dataset. Dataset has 80 columns and 312407 rows.

Its

taking more than 60 seconds to set simple attributes like split=TRUE,
usermissing=FALSE.

Here is the source code, assuming Dataset1 is the one that is large :-

myfunction - function()
{
cat(Before for loop:)
print(Sys.time())
for( colIndex in 1 : 80)
{
cat(Before Attr, colIndex)
print(Sys.time())

attributes(Dataset1[1]) - c(attributes(Dataset1[, colIndex]),

list(coldesc

= c(), usermissing = c(FALSE), missingvalues  = NULL, split = c(FALSE),
levelLabels = c()))

cat(After Attr:)
print(Sys.time())
}
cat(After for loop:)
print(Sys.time())
}

Its my feeling that R is passing all 312407 rows to set 'attributes' on a
cloumn.

Is there a more efficent way to do this?


Thanks,
SG

  [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.










--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

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


Re: [R] why is as.date function not working for me? (dd/mm/yyyy h:mm)

2014-02-06 Thread Luke Miller
as.Date produces Dates only, with no time information, even if you try
to supply it with hours + minutes.

For dates+times, use as.POSIXct() or as.POSIXlt() in place of
as.Date(). POSIXct produces a numeric value for the number of seconds
since your specified origin time (usually 1970-01-01 00:00), and
POSIXlt produces a list object with individual entries for year,
month, day, hour, minute etc. Be aware that time zones and daylight
savings transitions may suddenly come into play. See ?DateTimeClasses
for the gory details.

as.POSIXct(dates, format = %d/%m/%Y %H:%M)


On Thu, Feb 6, 2014 at 10:24 AM, jcrosbie ja...@crosb.ie wrote:
 Why am I know getting hours after I convert the date?

  dates - c('31/12/2013 0:00',  '31/12/2013 1:00',  '31/12/2013 2:00',
 '31/12/2013 3:00',  '31/12/2013 4:00',  '31/12/2013 5:00',  '31/12/2013
 6:00',  '31/12/2013 7:00',  '31/12/2013 8:00',  '31/12/2013 9:00',
 '31/12/2013 10:00', '31/12/2013 11:00',  '31/12/2013 12:00', '31/12/2013
 13:00', '31/12/2013 14:00', '31/12/2013 15:00',  '31/12/2013 16:00',
 '31/12/2013 17:00', '31/12/2013 18:00', '31/12/2013 19:00', '31/12/2013
 20:00', '31/12/2013 21:00', '31/12/2013 22:00', '31/12/2013 23:00',
 '01/01/2014 0:00')

 as.Date(dates, format=%d/%m/%Y %H:%M)
  [1] 2013-12-31 2013-12-31 2013-12-31 2013-12-31 2013-12-31
  [6] 2013-12-31 2013-12-31 2013-12-31 2013-12-31 2013-12-31
 [11] 2013-12-31 2013-12-31 2013-12-31 2013-12-31 2013-12-31
 [16] 2013-12-31 2013-12-31 2013-12-31 2013-12-31 2013-12-31
 [21] 2013-12-31 2013-12-31 2013-12-31 2013-12-31 2014-01-01





 --
 View this message in context: 
 http://r.789695.n4.nabble.com/why-is-as-date-function-not-working-for-me-dd-mm--h-mm-tp4684874.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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
https://stat.ethz.ch/mailman/listinfo/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] KnitR/RMarkdown: Is there a way to not print a section of the document?

2014-01-27 Thread Luke Miller
In the chunk options, you can use the argument echo = FALSE to
suppress display of the R code in the output.
 echo = FALSE=
# R code
@
This will still print out results from R that would be sent to the
command line (like print() statements, cat() statements, results from
summary(), etc), but the rest of the code in the chunk would be hidden
from the output document.

To make it easier to turn many code chunks on and off at once, define
a variable as TRUE/FALSE early in the document, and then use that
variable as the argument in the subsequent chunk options:

echo = FALSE=
showcode = FALSE
@

Every other chunk gets this argument:
 echo = showcode=
# R code. If showcode is FALSE, this code would be run, but not
displayed in the output document.
@


On Mon, Jan 27, 2014 at 4:49 PM, Jeff Johnson mrjeffto...@gmail.com wrote:
 I've been looking through the R documents to see if there's a way to not
 output certain chunks of code. I'm trying to present a document to a team
 of folks that won't necessarily be interested in the line-by-line code,
 though they are interested in the charts, etc. Thus, I'd like to not output
 certain chunks of code. Is there a way to suppress sections?

 Thank you.

 --
 Jeff

 [[alternative HTML version deleted]]

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



-- 
___
Luke Miller

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Y-axis label not plotting

2013-11-27 Thread Luke M
Dear R community

I am trying to make an XY plot that shows temperature (y axis) as a
function of time (x axis) but I am having some problems. When I use the
code shown below:

1. my plot does not show any of the y-axis labels even though there is
plenty of white space there (i.e.: I am getting no y-axis title, and no
y-axis labels at each tick mark). Is my command syntax incorrect?

2. Also, I was wondering... is there a way to tell R to plot the last 30
days of data in the x-axis?


Thank you so much in advance!!


Here's my code so far:

bdata=read.table('cleandata.asc',header=FALSE)
dates1 - strptime(paste(bdata$V2, bdata$V3), format=%m/%d/%Y %H:%M:%S)
temp1 = bdata[,4]
par(mar=c(5, 6, 4, 2))
plot(dates1, temp1,type=o,col=red,pch=20,xlab=x axis, main=my plot,
ylab=y axis, ylim=c(0,40), yaxp = c(0,40,10))


PS: just fyi, my data looks like this:

 temp1
 [1]  6.81 26.81 26.81 26.81 26.87 26.87 26.87 26.87 27.06 27.06 27.06
27.06
[13] 27.06 27.06 27.06 27.06 27.06 27.06 27.06 27.06 27.06 27.06 27.06
27.06
[25] 27.06 27.06 27.06 27.06 27.06 27.06 27.06 27.06 27.06 27.06 27.06
27.06
[37] 27.06 27.06 27.06 27.06 27.06 27.00 27.00 27.06 27.06 27.06 27.00
27.00
[49] 27.06 27.00 27.00 27.00 27.00 27.00 27.00 27.00 27.00 26.94 26.94
26.94
[61] 26.94 27.00 26.94 26.94 26.94 26.94 26.94 26.94 26.94 26.94 26.94
27.00
[73] 26.94 26.94 26.94 26.94 26.94 26.94 26.94 26.94 26.94


 dates1
 [1] 2013-01-12 18:10:28 HST 2013-10-24 18:10:43 HST
 [3] 2013-10-29 18:10:49 HST 2013-11-14 18:10:52 HST
 [5] 2013-11-14 18:12:10 HST 2013-11-14 18:12:12 HST
 [7] 2013-11-14 18:12:21 HST 2013-11-14 18:12:22 HST
 [9] 2013-11-14 18:17:10 HST 2013-11-14 18:17:11 HST
[11] 2013-11-14 18:17:13 HST 2013-11-14 18:17:14 HST
[13] 2013-11-14 18:17:15 HST 2013-11-14 18:17:17 HST
[15] 2013-11-14 18:17:18 HST 2013-11-14 18:17:20 HST
[17] 2013-11-14 18:17:21 HST 2013-11-14 18:17:22 HST
[19] 2013-11-14 18:17:24 HST 2013-11-14 18:17:25 HST
[21] 2013-11-14 18:17:26 HST 2013-11-14 18:17:28 HST
[23] 2013-11-14 18:17:29 HST 2013-11-14 18:17:30 HST
[25] 2013-11-14 18:17:32 HST 2013-11-14 18:17:33 HST
[27] 2013-11-14 18:17:34 HST 2013-11-14 18:17:36 HST
[29] 2013-11-14 18:17:37 HST 2013-11-14 18:17:38 HST
[31] 2013-11-14 18:17:40 HST 2013-11-14 18:17:41 HST
[33] 2013-11-14 18:17:42 HST 2013-11-14 18:17:44 HST
[35] 2013-11-14 18:17:45 HST 2013-11-14 18:17:46 HST
[37] 2013-11-14 18:18:47 HST 2013-11-14 18:18:48 HST
[39] 2013-11-14 18:18:50 HST 2013-11-14 18:18:51 HST
[41] 2013-11-14 18:18:52 HST 2013-11-14 18:18:54 HST
[43] 2013-11-14 18:18:55 HST 2013-11-14 18:18:56 HST
[45] 2013-11-14 18:18:58 HST 2013-11-14 18:18:59 HST
[47] 2013-11-14 18:19:10 HST 2013-11-14 18:19:11 HST
[49] 2013-11-14 18:19:12 HST 2013-11-14 18:19:14 HST
[51] 2013-11-14 18:19:15 HST 2013-11-14 18:19:16 HST
[53] 2013-11-14 18:19:18 HST 2013-11-14 18:19:19 HST
[55] 2013-11-14 18:19:20 HST 2013-11-14 18:19:22 HST
[57] 2013-11-14 18:19:23 HST 2013-11-14 18:20:24 HST
[59] 2013-11-14 18:20:26 HST 2013-11-14 18:20:27 HST
[61] 2013-11-14 18:20:29 HST 2013-11-14 18:20:30 HST
[63] 2013-11-14 18:20:31 HST 2013-11-14 18:20:33 HST
[65] 2013-11-14 18:20:34 HST 2013-11-14 18:20:35 HST
[67] 2013-11-14 18:20:37 HST 2013-11-14 18:20:38 HST
[69] 2013-11-14 18:20:39 HST 2013-11-14 18:20:41 HST
[71] 2013-11-14 18:20:42 HST 2013-11-14 18:20:43 HST
[73] 2013-11-14 18:20:45 HST 2013-11-14 18:20:46 HST
[75] 2013-11-14 18:20:47 HST 2013-11-14 18:20:49 HST
[77] 2013-11-14 18:20:50 HST 2013-11-14 18:20:51 HST
[79] 2013-11-14 18:20:53 HST 2013-11-14 18:20:54 HST
[81] 2013-11-14 18:20:55 HST

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Y-axis label not plotting

2013-11-27 Thread Luke M
Thanks for the follow-up. Per your suggestion, I was able to plot the data
for the last 30 days with no problem.

However... I am still confused about the y-axis labels (values, title, etc)
not plotting. If the scripting works as it should, what could cause the
labels not to show up? A while ago I think that I accidentally changed
something (not sure what) on the default settings (I was trying to learn
how to make plots), and I wonder if this could cause the problem I am
having...




On Wed, Nov 27, 2013 at 12:23 AM, Jim Lemon j...@bitwrit.com.au wrote:

 On 11/27/2013 05:32 PM, Luke M wrote:

 Dear R community

 I am trying to make an XY plot that shows temperature (y axis) as a
 function of time (x axis) but I am having some problems. When I use the
 code shown below:

 1. my plot does not show any of the y-axis labels even though there is
 plenty of white space there (i.e.: I am getting no y-axis title, and no
 y-axis labels at each tick mark). Is my command syntax incorrect?

 2. Also, I was wondering... is there a way to tell R to plot the last 30
 days of data in the x-axis?


 Thank you so much in advance!!


 Here's my code so far:

 bdata=read.table('cleandata.asc',header=FALSE)
 dates1- strptime(paste(bdata$V2, bdata$V3), format=%m/%d/%Y %H:%M:%S)
 temp1 = bdata[,4]
 par(mar=c(5, 6, 4, 2))
 plot(dates1, temp1,type=o,col=red,pch=20,xlab=x axis, main=my
 plot,
 ylab=y axis, ylim=c(0,40), yaxp = c(0,40,10))


 PS: just fyi, my data looks like this:

  Hi Luke,
 Thanks for including the data. When I plot it, I get both y axis label and
 y axis tick labels.

 If you only want the last 30 days, you could select them like this:

 last30-dates1 = strptime(2013-10-14,%Y-%m-%d)
 plot(dates1[last30],temp1[last30],type=o,col=red,pch=20,

  xlab=x axis, main=my plot, ylab=y axis, ylim=c(0,40),
  yaxp = c(0,40,10))

 Jim


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] gmmBoost creating huge 500+ gb vectors

2013-10-28 Thread Luke Miner
I'm trying to run bGLMM on a large dataset and it is failing after trying to 
create huge vectors with the error:
Error: cannot allocate vector of size 553.7 Gb
The dataset that I'm using is fairly large, around 1.5 million observations. 
The command is as follows:
boost1 - bGLMM(A~ B + C, rnd = list(D=~1), data = train, family =binomial)
A is binary, B and C are continuous and D is a factor variable with 250,000 
levels that I'm trying to model as a random effect.
A similar model runs fine on lme4. Is my dataset simply much too large for this 
package or am I doing something obviously wrong?
  
[[alternative HTML version deleted]]

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


Re: [R] save/load doubles memory [oops]

2013-09-17 Thread luke-tierney

At this point R's serialization format only preserves sharing of
environments; any other sharing is lost. Changing this will require an
extensive rewrite of serialization. It would be useful to have this,
especially as we are trying to increase sharing/decrease copying, but
it isn't likely any time soon.

Best,

luke

On Tue, 17 Sep 2013, Ross Boylan wrote:


On Tue, 2013-09-17 at 12:06 -0700, Ross Boylan wrote:

Saving and loading data is roughly doubling memory use.  I'm trying to
understand and correct the problem.

Apparently I had the process memories mixed up: R1 below was the one
with 4G and R2 with 2G.  So there's less of a mystery.  However...


R1 was an R process using just over 2G of memory.
I did save(r3b, r4, sflist, file=r4.rdata)
and then, in a new process R2,
load(file=r4.rdata)

R2 used just under 4G of memory, i.e., almost double the original
process.  The r4.rdata file was just under 2G, which seemed like very
little compression.

r4 was created by
r4 - sflist2stanfit(sflist)

I presume that r4 and sflist shared most of their memory.
The save() apparently lost the information that the memory was shared,
doubling memory use.

Still wondering if this is going on.


R 2.15.1, 64 bit on linux.

First, does my diagnosis sound right?  The reports of memory use in R2
are quite a bit lower than the process footprint; is that normal?

gc()  # after loading data

used   (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells   1988691  106.33094291  165.3   2432643  130.0
Vcells 266976864 2036.9  282174979 2152.9 268661172 2049.8

rm(r4)
gc()

used   (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells   1949626  104.23094291  165.3   2432643  130.0
Vcells 190689777 1454.9  282174979 2152.9 268661172 2049.8

r4 - sflist2stanfit(sflist)
gc()

used   (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells   1970497  105.33094291  165.3   2432643  130.0
Vcells 228827252 1745.9  296363727 2261.1 268661172 2049.8



It seems the recreated r4 used about 300M less memory than the one read
in from disk.  This suggests that some of the sharing was lost in the
save/load  process.



Even weirder, R1 reports memory use well beyond the memory I show the
process using (2.2G)

Not a mystery after getting the right processes.  Actually, I'm a little
surprised the process memory is less than the max used memory; I thought
giving back memory was not possible on Linux.

gc()

 used   (Mb) gc trigger   (Mb)  max used   (Mb)
 Ncells   3640941  194.55543382  296.1   5543382  296.1
 Vcells 418720281 3194.6  553125025 4220.1 526708090 4018.5


Second, what can I do to avoid the problem?


Now a more modest problem, though still a problem.


I guess in this case I could not save r4 and recreate it, but is there a
more general solution?

If I did myboth - list(r4, sflist) and
save(myboth, file=myfile)
would that be enough to keep the objects together?  Judging from the
size of the file, it seems not.

Even if the myboth trick worked it seems like a kludge.

Ross Boylan



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



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Issue with Imports in NAMESPACE

2013-06-25 Thread luke-tierney

On Tue, 25 Jun 2013, Duncan Murdoch wrote:


On 13-06-25 7:14 AM, Søren Højsgaard wrote:

Dear Duncan,

Excellent, thanks!

Maybe this is worth a remark in a future version of Writing R Extensions 
(including that those local copies are not exported again with 
exportPattern(^[[:alpha:]]+)).


It is mentioned that they can be exported.  The fact that exportPattern 
doesn't see them might be a bug.


I don't think it's a bug -- including all imports would usually bring
in way too much.

In general re-exporting is probably not such a great idea since the
help system isn't aware of the import/export chain. I don't know if R
CMD check complains if you don't provide your own help page; if it
doesn't it probably should.  I also don't recall if we have a
mechanism for such a help page on an import/export to just link to the
real page.

Best,

luke




Duncan



Thanks!

Søren

-Original Message-
From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com]
Sent: 25. juni 2013 13:02
To: Søren Højsgaard
Cc: R hELP (r-h...@stat.math.ethz.ch)
Subject: Re: [R] Issue with Imports in NAMESPACE

On 13-06-25 6:50 AM, Søren Højsgaard wrote:

Dear all,
In my gRbase package I have up until now Depend-ed on RBGL (from 
Bioconductor), but good people have convinced me that I should use 
Import-it instead because I only use few functions from RBGL.


In DESCRIPTION I therefore now have
Imports: Matrix,RBGL

In NAMESPACE I now have
importFrom(RBGL, maxClique, is.triangulated, separates)

The package compiles without complaints, but I have noticed that if I 
start a fresh R-session, then maxClique etc. from RBGL is NOT available 
for interactive use in my session:

library(gRbase)
maxClique

Error: object 'maxClique' not found

1) Is this as it should be?

2) If yes, is there any other way in which maxClique can be imported for 
interactive use without Depend-ing the whole RBGL package?


The importFrom directive effectively makes local copies of those functions 
in your package (with the usual caveats that copies aren't as inefficient 
as you might think).  If you want to export them, you need to add them to 
the exports list.


Duncan Murdoch



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



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] attr vs attributes

2013-05-13 Thread luke-tierney

There is a certain logic to the behavior. In the complex assignment in
the second line of

x - 1
attributes(x)[[attrName]] - 2012

what happens is first the equivalent of

a - attributes(x) ## a is NULL
a[[attrName]] - 2012 ## a is now a numeric vector

and then

attributes(x) - a ## error because a is not a 'list'

In contrast

a - attributes(x) ## a is NULL
a - 2012:2013 ## a is now a 'list' with one element, 2012:2013

This could be 'fixed' by having `attributes-` coerce its right hand
side to a list if that is possible (and raises questions of whether we
should just promote atomic vectors or allow the generic as.list to be
called).

I'm not convinced such a 'fix' would be a good thing as it might mask
other bugs that are now being caught.

luke

On Fri, 10 May 2013, Duncan Murdoch wrote:


On 13-05-10 2:06 PM, William Dunlap wrote:

Thanks.  I looks like my example worked because the value of the new
attribute had a length greater than 1.  That difference in behavior
smells like a bug.


Yes, definitely looks like one.  I'll submit the bug report; I hope someone 
else will fix it.


Duncan Murdoch



{ x - 1 ; attributes(x)[[attrName]] - 2012 ; str(x) }
   Error in attributes(x)[[attrName]] - 2012 :
attributes must be a list or NULL
{ x - 1 ; attributes(x)[[attrName]] - 2012:2013 ; str(x) }
atomic [1:1] 1
   - attr(*, attrName)= int [1:2] 2012 2013

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

From: Murat Tasan [mailto:mmu...@gmail.com]
Sent: Friday, May 10, 2013 10:56 AM
To: William Dunlap
Cc: r-help@r-project.org
Subject: Re: [R] attr vs attributes

sure, here's a series of commands/outputs (using R 3.0.0):


x - letters[1:4]
y - foo
attributes(x)

NULL

attributes(x)[[y]] - bar

Error in attributes(x)[[y]] - bar : attributes must be a list or NULL

attr(x, y) - bar
attributes(x)

$foo
[1] bar


attributes(x)[[y]] - newbar
attributes(x)

$foo
[1] newbar





cheers!

-m


On Fri, May 10, 2013 at 12:31 PM, William Dunlap 
wdun...@tibco.commailto:wdun...@tibco.com wrote:

attributes(my_obj)[[my_attr_name]] - my_attr_value


...fails when my_obj doesn't already have an attribute named my_attr_name.

Do you have an example of this?  In R-2.15.3 I don't see that problem:
 my_obj - 37:41
 my_attr_name - myAttr
 my_attr_value - as.roman(2012:2013)
 attributes(my_obj)[[my_attr_name]] - my_attr_value
 my_obj
[1] 37 38 39 40 41
attr(,myAttr)
[1] MMXII  MMXIII

attributes(my_obj)[[anotherAttrName]] - another attribute value
my_obj
   [1] 37 38 39 40 41
   attr(,myAttr)
   [1] MMXII  MMXIII
   attr(,anotherAttrName)
   [1] another attribute value

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.comhttp://tibco.com



-Original Message-
From: r-help-boun...@r-project.orgmailto:r-help-boun...@r-project.org 
[mailto:r-help-boun...@r-project.orgmailto:r-help-boun...@r-project.org] 
On Behalf

Of Murat Tasan
Sent: Friday, May 10, 2013 8:16 AM
To: Duncan Murdoch
Cc: r-help@r-project.orgmailto:r-help@r-project.org
Subject: Re: [R] attr vs attributes

thanks, both.

the only real difference between the two approaches that i can see is when
assigning _new_ attributes to an object where the attribute name is itself
variable.
something like this:


attributes(my_obj)[[my_attr_name]] - my_attr_value


...fails when my_obj doesn't already have an attribute named my_attr_name.
BUT(!) it does work just fine when the attribute named my_attr_name is
already attached to my_obj.

i guess in the end attr(...) is just easier, but i can also see a spot of
confusion in the 'attributes(x)[[y]] - z' working sometimes for folks and
sometimes not.

(to be clear, it's pretty easy to figure out when it does and doesn't 
work,

but if there's a new programmer coming along and it works the first time,
when the upstream code changes a bit (i.e. the attribute name changes) and
this attribute-setting line then fails, it could be very confusing :-)

thanks for the thoughts!

cheers,

-m




On Fri, May 10, 2013 at 10:58 AM, Duncan Murdoch
murdoch.dun...@gmail.commailto:murdoch.dun...@gmail.comwrote:


On 10/05/2013 10:50 AM, Rui Barradas wrote:


Hello,

There's at least one example where only the form attr(x, foo) - bar
would work, not the other form. If you want to set attributes
programatically, use the first form, like in the function below. Note
that the example is artificial.


setAttr - function(x, attrib, value){
 attr(x, attrib) - value
 x
}

x - 1:4
setAttr(x, foo, bar)


You cannot make

attribute(x)$attrib - value



But

attributes(x)[[attrib]] - value

would be fine.  I don't know why Murat thought there would be different
consistency checks; I'd assume the main difference would be that attr()
would be quicker.  (It does a lot less: attributes(x)[[attrib]] - value
essentially does

temp - attributes(x)
temp[[attrib]] - value
attributes(x) - temp

and there are a lot of wasted operations there.)

Duncan Murdoch

Re: [R] Unexpected behavior looping through sequence of dates

2013-03-09 Thread luke-tierney

R's for loop is only designed to iterato over primitive types. The
help file says of the seq argument:

 seq: An expression evaluating to a vector (including a list and an
  expression) or to a pairlist or ‘NULL’.  A factor value will
  be coerced to a character vector.

[This could be more emphatic by stating that any class attributes are
igonred or something of that nature.]

Having for() do anything else would require designing an iteration
protocol -- probably would be nice in principle but not easy to do.

Best,

luke

On Sat, 9 Mar 2013, Peter Ehlers wrote:


On 2013-03-09 11:14, R. Michael Weylandt wrote:
On Sat, Mar 9, 2013 at 6:50 PM, David Winsemius dwinsem...@comcast.net 
wrote:
I was unable to find the reason for the original coercion in the 
help(for) page or the R
Language Definition entry regarding for-loops. On the hunch that coercion 
via as.vector

might be occurring,


Behaviorally, it seems to, but the code for do_for in eval.c has
factors special-cased to call
asCharacterFactor so that might not be a robust detail to rely on. The
relevant behavior seems instead to be that there's a
switch on val_type which creates the loop index but doesn't copy all
attributes (like class)

Note that this means a user's as.vector wouldn't be called here:

as.vector.flub - function(x, ...) letters[x]

foo - 1:5
class(foo) - flub

as.vector(foo)

for(j in foo) {print(j); print(class(j))}

as.vector.grub - function(x, ...) match(x, letters)

bar - letters[1:5]
class(bar) - grub

as.vector(bar)

for(j in bar) {print(j); print(class(j))}

Cheers,
Michael


I think that Michael is right - the problem is with val_type
in the do_for code.

Here's a simplified version of Alexandre's example:

d - as.Date(2013-03-10)
for(i in seq_along(d)) print(i)
#[1] 1

for(i in d) print(i)
#[1] 15774
where we might have expected to see 2013-03-10.

The essential line in the do_for code seems to me to be:

val_type = TYPEOF(val);

?typeof tells us that R does not have a 'date' type, so:

typeof(d)
#[1] double

And the for-loop results follow.

Peter Ehlers

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



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Unexpected behavior looping through sequence of dates

2013-03-09 Thread luke-tierney

On Sat, 9 Mar 2013, Alexandre Sieira wrote:


Thanks for the clarification, Luke.

That is really counter-intuitive behavior. I 100% agree with you that the for 
documentation should state that assumption explicitly.

I would also like to suggest changing the for implementation to issue a warning if the 
seq argument is a vector of a non-primitive type. That would have saved me a few hours 
of debugging in the last few days, so I imagine it must be relevant for more people as well.


Issuing a warning unconditioally would result in far to many spurious
warnings.  for() works perfecly fine now for most objects with a class
attribute. I don't see a reasonable way to detect the subset of cases
where this is not true (other than registering a list of classes for()
should warn about, which might be feasible, though might refult in a
significant performance hit.)

Best,

luke



--
Alexandre Sieira
CISA, CISSP, ISO 27001 Lead Auditor

The truth is rarely pure and never simple.
Oscar Wilde, The Importance of Being Earnest, 1895, Act I


Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Saturday, 9 de March de 2013 at 13:10, luke-tier...@uiowa.edu wrote:


R's for loop is only designed to iterato over primitive types. The
help file says of the seq argument:

seq: An expression evaluating to a vector (including a list and an
expression) or to a pairlist or ¡NULL¢. A factor value will
be coerced to a character vector.

[This could be more emphatic by stating that any class attributes are
igonred or something of that nature.]

Having for() do anything else would require designing an iteration
protocol -- probably would be nice in principle but not easy to do.

Best,

luke

On Sat, 9 Mar 2013, Peter Ehlers wrote:


On 2013-03-09 11:14, R. Michael Weylandt wrote:

On Sat, Mar 9, 2013 at 6:50 PM, David Winsemius dwinsem...@comcast.net 
(mailto:dwinsem...@comcast.net)
wrote:

I was unable to find the reason for the original coercion in the
help(for) page or the R
Language Definition entry regarding for-loops. On the hunch that coercion
via as.vector
might be occurring,




Behaviorally, it seems to, but the code for do_for in eval.c has
factors special-cased to call
asCharacterFactor so that might not be a robust detail to rely on. The
relevant behavior seems instead to be that there's a
switch on val_type which creates the loop index but doesn't copy all
attributes (like class)

Note that this means a user's as.vector wouldn't be called here:

as.vector.flub - function(x, ...) letters[x]

foo - 1:5
class(foo) - flub

as.vector(foo)

for(j in foo) {print(j); print(class(j))}

as.vector.grub - function(x, ...) match(x, letters)

bar - letters[1:5]
class(bar) - grub

as.vector(bar)

for(j in bar) {print(j); print(class(j))}

Cheers,
Michael




I think that Michael is right - the problem is with val_type
in the do_for code.

Here's a simplified version of Alexandre's example:

d - as.Date(2013-03-10)
for(i in seq_along(d)) print(i)
#[1] 1

for(i in d) print(i)
#[1] 15774
where we might have expected to see 2013-03-10.

The essential line in the do_for code seems to me to be:

val_type = TYPEOF(val);

?typeof tells us that R does not have a 'date' type, so:

typeof(d)
#[1] double

And the for-loop results follow.

Peter Ehlers

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




--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa Phone: 319-335-3386
Department of Statistics and Fax: 319-335-3017
Actuarial Science
241 Schaeffer Hall email: luke-tier...@uiowa.edu (mailto:luke-tier...@uiowa.edu)
Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu







--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Hard Stop?

2013-02-07 Thread luke-tierney

There are 4 ways, other than generating a core dump :-), that could
fit your vague desctiption:

Call q(no); this is the only way to avoid 'finally' expressions
in tryCatch if that is really what you want.

You can invoke an abort restart; there will be one established
by the intepreter, but there may be others. You can choose the
one you want programmatically.  If you use the outer-most one
from the interpreter then what happens depends on whether R is
running interactively or not.

You can call stop() with a condition argument that is not an error
or a warning to avoid any handlers established by tryCatch or
withCallingHandlers to intercept warnings or errors. This will
drop down to stop's default handling of errors (i.e. print a
message and invoke the nearest abort restart).

You can capture an unevaluated return() call and evaluate it at
the point from which you want to escape. This is what callCC does,
and using callCC would be the recommended way to do this if this
is what you want.

[R's condition handling is based on Common Lisp's; a good reference
for that is
http://www.nhplace.com/kent/Papers/Condition-Handling-2001.html. Some
day there will be an R version of this document.]

What choice is appropriate depends on exactly what you want to have
happen after you execute your Hard Stop and whether you own, or need
to own, the code that receives the transfer of control initiated by
your 'Hard Stop.

Best,

luke

On Thu, 7 Feb 2013, Duncan Murdoch wrote:


On 06/02/2013 8:33 PM, ivo welch wrote:

is it possible to throw a stop() that is so hard that it will escape
even tryCatch?


You can signal a condition that is not an error, and if tryCatch hasn't been 
written to catch it, it will stop.   For example,


g - function() {
 tryCatch(f(), error=function(e) NULL
 cat(Still running\n)
}

f - function() stop(Regular error)  # This won't stop g()
g()


f  - function() stop(simpleCondition(I mean it!)) # This will
g()

Of course, you can catch simpleConditions too if you try.

Duncan Murdoch

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



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Codetools Query (repost)

2013-01-16 Thread luke-tierney

You really don't want to use internals like isBaseVar as there is no
guarantee they will continue to exist.  Even collectUsage and otehr
things mentioned on the same page may need to change if this is
reimplemented.

The most robust approach is to use findGlobals and omit what you don't
want, e.g.

 omit - ls(package:base, all.names=TRUE)
 setdiff(findGlobals(moo),omit)
[1] y

If you do want to use chollectUsage you could use something like

funs - new.env()
omit - ls(package:base, all.names=TRUE)
enter - function(type, v, e, w){
if (! v %in% omit)
assign(v, TRUE, funs)
}
collectUsage(moo, enterGlobal = enter)

If %in% is too slow create a hashed envorinment and use exists().

Best,

luke

On Tue, 15 Jan 2013, Saptarshi Guha wrote:


Sorry for reposting,  i keep forgetting this should be plain text.
Will not make this mistake again

Hello,

The following code

moo - function(a=1){ x=1; x=x+y}
funs - new.env()
enter - function(type, v, e, w){
 assign(v, TRUE, funs)
}
library(codetools)
collectUsage(moo, enterGlobal = enter)


adds + to the environment funs i.e.

funs: = { + y

How can i ignore variables which are present in base, utils, stat
environments from being added (equivalently(?) symbols present in R
when R is started)

I tried



funs - new.env()
enter - function(type, v, e, w){
 if(codetools:::isBaseVar(v, w$env) || codetools:::isStatsVar(v, w$env)
|| codetools:::isUtilsVar(v, w$env) || v == Quote)
   return()
 assign(v, TRUE, funs)
}

library(codetools)
collectUsage(moo, enterGlobal = enter)

but this threw

Error in exists(v, envir = e, inherits = FALSE, mode = function) :
 invalid 'envir' argument

Cheers

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



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] try()-function does not catch error in BATCH-job if Matrix is loaded

2013-01-08 Thread luke-tierney

The work-around was actually put in plae prior to the release of R
2.15.2, so updating your R to the current released version will
resolve this.

Best,

luke

On Mon, 7 Jan 2013, luke-tier...@uiowa.edu wrote:


This is due to long-staning issue in methods internals, which are
involved because loading Matrix shadows base::mean with Matrix::mean.
A work-around has been in place in R_devel for some time; a proper fix
may come at some point in the future. So if your real code doesn't
need the moficied mean from Matrix you can use base::mean; otherwise
you will have to use an R-devel snapshot.

Best,

luke

On Mon, 7 Jan 2013, Sarah Brockhaus wrote:


Hello,

In my simulation I use the try()-function to catch possible errors when 
fitting models. I run the simulationon a Linux-server using the command  R 
CMD BATCH nameOfFile.R .  When executing the code as batch-job I get the 
problem that the execution is halted without giving an error message. But 
when I run the code interactivly the error is catched by try() as it would 
be expected.


The problem is somewhat strange as it only occurs when the code is executed 
as a batch-job and when the package Matrix is loaded.


I wrote a small example reproducing the error. (In my code the error occurs 
in mgcv:::fixDependence, which looks like the code I'm using below in order 
to get a small reproducible example. I realized that the code  makes no 
sense...)


##
library(Matrix)

R - matrix(abs(rnorm(25)), 5, 5)
r0 - r - nrow(R)

# while-loop produces error that should be catched by the function try()
try(
while (mean(R[r0:r, r0:r])  0) r0 - r0 - 1
)

# so Hello should be printed
print(Hello)
##

I use R version 2.15.1 (2012-06-22) on a x86_64-pc-linux-gnu (64-bit) 
platform.


I would be grateful for help.

Best regards,
Sarah Brockhaus

PHD-student
Department of Statistics
University of Munich

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.






--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] try()-function does not catch error in BATCH-job if Matrix is loaded

2013-01-07 Thread luke-tierney

This is due to long-staning issue in methods internals, which are
involved because loading Matrix shadows base::mean with Matrix::mean.
A work-around has been in place in R_devel for some time; a proper fix
may come at some point in the future. So if your real code doesn't
need the moficied mean from Matrix you can use base::mean; otherwise
you will have to use an R-devel snapshot.

Best,

luke

On Mon, 7 Jan 2013, Sarah Brockhaus wrote:


Hello,

In my simulation I use the try()-function to catch possible errors when 
fitting models. I run the simulationon a Linux-server using the command  R 
CMD BATCH nameOfFile.R .  When executing the code as batch-job I get the 
problem that the execution is halted without giving an error message. But 
when I run the code interactivly the error is catched by try() as it would be 
expected.


The problem is somewhat strange as it only occurs when the code is executed 
as a batch-job and when the package Matrix is loaded.


I wrote a small example reproducing the error. (In my code the error occurs 
in mgcv:::fixDependence, which looks like the code I'm using below in order 
to get a small reproducible example. I realized that the code  makes no 
sense...)


##
library(Matrix)

R - matrix(abs(rnorm(25)), 5, 5)
r0 - r - nrow(R)

# while-loop produces error that should be catched by the function try()
try(
while (mean(R[r0:r, r0:r])  0) r0 - r0 - 1
)

# so Hello should be printed
print(Hello)
##

I use R version 2.15.1 (2012-06-22) on a x86_64-pc-linux-gnu (64-bit) 
platform.


I would be grateful for help.

Best regards,
Sarah Brockhaus

PHD-student
Department of Statistics
University of Munich

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



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] easy way to fit saturated model in sem package?

2012-07-13 Thread luke-tierney

They look fine to me.

luke

On Fri, 13 Jul 2012, Joshua Wiley wrote:


Dear John,

Thanks very much for the reply.  Looking at the optimizers, I had
thought that the objectiveML did what I wanted.  I appreciate the
clarification.

I think that multiple imputation is more flexible in some ways because
you can easy create different models for every variable.  At the same
time, if the assumptions hold, FIML is equivalent to multiple
imputation, and considerably more convenient.  Further, I suspect that
in many circumstances, either option is equal to or better than
listwise deletion.

In my case, I am working on some tools primarily for data exploration,
in a SEM context (some characteristics of individual variables and
then covariance/correlation matrices, clustering, etc.) and hoped to
include listwise/pairwise/FIML as options.

I will check out the lavaan package.

Thanks again for your time,

Josh

On Thu, Jul 12, 2012 at 8:20 AM, John Fox j...@mcmaster.ca wrote:

Dear Joshua,

If I understand correctly what you want to do, the sem package won't do it.
That is, the sem() function won't do what often is called FIML estimation
for models with missing data. I've been thinking about implementing this
feature, and don't think that it would be too difficult, but I can't promise
when and if I'll get to it. You might also take a look at the lavaan
package.

As well, I must admit to some skepticism about the FIML estimator, as
opposed to approaches such as multiple imputation of missing data. I suspect
that the former is more sensitive than the latter to the assumption of
multinormality.

Best,
 John


John Fox
Senator William McMaster
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
project.org] On Behalf Of Joshua Wiley
Sent: July-12-12 2:53 AM
To: r-help@r-project.org
Cc: John Fox
Subject: [R] easy way to fit saturated model in sem package?

Hi,

I am wondering if anyone knows of an easy way to fit a saturated model
using the sem package on raw data?  Say the data were:

mtcars[, c(mpg, hp, wt)]

The model would estimate the three means (intercepts) of c(mpg, hp,
wt).  The variances of c(mpg, hp, wt).  The covariance of mpg
with hp and wt and the covariance of hp with wt.

I am interested in this because I want to obtain the MLE mean vector
and covariance matrix when there is missing data (i.e., the sum of the
case wise likelihoods or so-called full information maximum
likelihood).  Here is exemplary missing data:

dat - as.matrix(mtcars[, c(mpg, hp, wt)])
dat[sample(length(dat), length(dat) * .25)] - NA dat -
as.data.frame(dat)

It is not too difficult to write a wrapper that does this in the OpenMx
package because you can easily define paths using vectors and get all
pairwise combinations using:

combn(c(mpg, hp, wt), 2)

but I would prefer to use the sem package, because OpenMx does not work
on 64 bit versions of R for Windows x64 and is not available from CRAN
presently.  Obviously it is not difficult to write out the model, but I
am hoping to bundle this in a function that for some arbitrary data,
will return the FIML estimated covariance (and correlation matrix).
Alternately, if there are any functions/packages that just return FIML
estimates of a covariance matrix from raw data, that would be great
(but googling and using findFn() from the sos package did not turn up
good results).

Thanks!

Josh


--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group University of
California, Los Angeles https://joshuawiley.com/

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









--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] easy way to fit saturated model in sem package?

2012-07-13 Thread luke-tierney

Apologies -- replied to the wrong message.

luke

On Fri, 13 Jul 2012, luke-tier...@uiowa.edu wrote:


They look fine to me.

luke

On Fri, 13 Jul 2012, Joshua Wiley wrote:


Dear John,

Thanks very much for the reply.  Looking at the optimizers, I had
thought that the objectiveML did what I wanted.  I appreciate the
clarification.

I think that multiple imputation is more flexible in some ways because
you can easy create different models for every variable.  At the same
time, if the assumptions hold, FIML is equivalent to multiple
imputation, and considerably more convenient.  Further, I suspect that
in many circumstances, either option is equal to or better than
listwise deletion.

In my case, I am working on some tools primarily for data exploration,
in a SEM context (some characteristics of individual variables and
then covariance/correlation matrices, clustering, etc.) and hoped to
include listwise/pairwise/FIML as options.

I will check out the lavaan package.

Thanks again for your time,

Josh

On Thu, Jul 12, 2012 at 8:20 AM, John Fox j...@mcmaster.ca wrote:

Dear Joshua,

If I understand correctly what you want to do, the sem package won't do 
it.

That is, the sem() function won't do what often is called FIML estimation
for models with missing data. I've been thinking about implementing this
feature, and don't think that it would be too difficult, but I can't 
promise

when and if I'll get to it. You might also take a look at the lavaan
package.

As well, I must admit to some skepticism about the FIML estimator, as
opposed to approaches such as multiple imputation of missing data. I 
suspect

that the former is more sensitive than the latter to the assumption of
multinormality.

Best,
 John


John Fox
Senator William McMaster
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
project.org] On Behalf Of Joshua Wiley
Sent: July-12-12 2:53 AM
To: r-help@r-project.org
Cc: John Fox
Subject: [R] easy way to fit saturated model in sem package?

Hi,

I am wondering if anyone knows of an easy way to fit a saturated model
using the sem package on raw data?  Say the data were:

mtcars[, c(mpg, hp, wt)]

The model would estimate the three means (intercepts) of c(mpg, hp,
wt).  The variances of c(mpg, hp, wt).  The covariance of mpg
with hp and wt and the covariance of hp with wt.

I am interested in this because I want to obtain the MLE mean vector
and covariance matrix when there is missing data (i.e., the sum of the
case wise likelihoods or so-called full information maximum
likelihood).  Here is exemplary missing data:

dat - as.matrix(mtcars[, c(mpg, hp, wt)])
dat[sample(length(dat), length(dat) * .25)] - NA dat -
as.data.frame(dat)

It is not too difficult to write a wrapper that does this in the OpenMx
package because you can easily define paths using vectors and get all
pairwise combinations using:

combn(c(mpg, hp, wt), 2)

but I would prefer to use the sem package, because OpenMx does not work
on 64 bit versions of R for Windows x64 and is not available from CRAN
presently.  Obviously it is not difficult to write out the model, but I
am hoping to bundle this in a function that for some arbitrary data,
will return the FIML estimated covariance (and correlation matrix).
Alternately, if there are any functions/packages that just return FIML
estimates of a covariance matrix from raw data, that would be great
(but googling and using findFn() from the sos package did not turn up
good results).

Thanks!

Josh


--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group University of
California, Los Angeles https://joshuawiley.com/

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












--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Efficient distance calculation on big matrix

2012-06-18 Thread luke-tierney

It so happens I have been looking at very similar changes, as well as
adding multi-threading support for dist(); these should make it into
R-devel later this summer.

Best,

luke

On Sun, 17 Jun 2012, Stefan Evert wrote:




I'm working on analyzing a large data set, lets asume that
dim(Data)=c(1000,8700). I want to calculate the canberra distance
between the columns of this matrix, and using a toy example ('test' is
a matrix filled with random numbers 0-1):


system.time(d-as.matrix(dist(t(test), method = canberra, diag = FALSE, upper 
= FALSE, p = 2)))

   user   system  elapsed
1417.7133.219 1421.144
The system.time results also confuse me a bit, since 99% of the time
is not system time but user time. What does that mean?


User time is the time that R spends working on your problem; system time refers 
to tasks done by the operating system, e.g. disk access, managing locks and, 
most importantly, swapping when you run out of RAM.  With multi-threading, 
system time can be much larger than the time that has actually elapsed.



Is there any way to calculate the distance which would take less time?


Well, one thing you can do is to get a faster computer. :-)  The command above 
takes only 670 seconds on my MacBook Pro (without multi-threading).

Calculating a distance matrix is an expensive computation.  In your example, R 
has to carry out (8700 * 8700 * 1000) / 2 = 37.8 billion floating point 
divisions.  With approx. 27 clock cycles per division (according to tables I've 
found on the Web), this takes at least 340 seconds even on a 3GHz CPU (and 
ignoring memory access, addition/subtraction, loops, etc.).

You can shave off some of the time if you implement the distance calculation in 
C, inline the code to avoid callback functions in loops, operate on columns of 
the matrix directly (which should be more cache-friendly than rows) and don't 
check for NA's, NaN's and other degenerate cases.

I've done just that in my experimental R package wordspace, which isn't on 
CRAN yet:


library(wordspace)
A - matrix(runif(8.7e6), 1000, 8700)



system.time(d1 - as.matrix(dist(t(A), method=canberra)))

  user  system elapsed
669.207   2.724 669.305


system.time(d2 - dist.matrix(A, method=canberra, byrow=FALSE))

  user  system elapsed
250.534   0.784 250.301


all(d1 == d2)

[1] TRUE

If you aren't tied to Canberra distance, you can use a less expensive metric 
such as the Manhattan distance for an additional, more substantial speed boost:


system.time(d3 - dist.matrix(A, method=manhattan, byrow=FALSE))

  user  system elapsed
42.488   0.999  43.569

This is still single-threaded, so you can run multiple of these calculations in 
parallel depending on how many cores your server has.

Hope this helps,
Stefan


PS: In case you'd like to give it a try yourself and aren't daunted by a 
complete lack of documentation:

svn checkout svn://scm.r-forge.r-project.org/svnroot/wordspace/pkg


[ ev...@linglit.tu-darmstadt.de | http://purl.org/stefan.evert ]

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



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] eclipse cran r

2012-06-12 Thread Luke Miller
Read through this page on float (figure) placement:
http://en.wikibooks.org/wiki/LaTeX/Floats,_Figures_and_Captions

In particular, trying including \usepackage{float} in your TeX preamble
and then place figures using the big [H] option:

\begin{figure}[H]

That may accomplish what you want in terms of placing figures in the
desired location.


On Tue, Jun 12, 2012 at 11:13 AM, Trying To learn again
tryingtolearnag...@gmail.com wrote:

 Hi JEssica

 I have tried but for the moment I´m getting crazyso I let for the
 future to understand for instance why the viewer doesn´t goes, and so on.


 Actually I´m using Tex Maker and I attach code using
 funtion \begin{lstlisting} so on


 The only inconvenience in Latex is always is to put plots where you
 want.
 I use this figute code location but it makes wat it wants.

 \begin{figure}[!h]

 \centering

 \includegraphics[scale=0.2]{vata.eps}\\

 \end{figure}


 I know this is a R forum (sorry for my unformal way of typing yesterday
 Michael I wrotte from my phone and I was very  tired, is not a
 justification I know anyway) but I´m sure that if someone has treat LAtex
 with eps or png images sure has the same problem. I read that using
 eclipse
 and sweave this thinks improveat least I have triedĄĄĄ

 Many thanks to all.


 2012/6/12 Jessica Streicher j.streic...@micromata.de

  http://www.walware.de/goto/statet
  eclipse plugin
 
  Having tried both sweave and knitr:
  Knitr is easier to set up by far, but i don't like its documentation, so
  i
  stayed with Sweave.
  I needed a few days to get it running properly though, and it needed
  workarounds.
 
  Am 12.06.2012 um 00:32 schrieb Trying To learn again:
 
   hi i see you can create latex pdf files using eclipse and that cran r
  code
   can be put on it direcctly. I have tried but it seems very difficult
  there
   is an easy way step by step manual and explaining all programs and
  folders
   needed?
  
         [[alternative HTML version deleted]]
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/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
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




--
___
Luke Miller
Postdoctoral Researcher
Hopkins Marine Station, Stanford University
120 Ocean View Blvd
Pacific Grove, CA 93950
831-655-6208

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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-buffering problem, this time with an example.

2012-06-04 Thread luke-tierney

FOR what it's worth this dev.hold/dev/flush combination does not seem
to prevent flickering on the quartz device on Macs.

Best,

luke

On Sat, 2 Jun 2012, Duncan Murdoch wrote:


On 12-06-02 4:02 PM, Daniel Carr wrote:

Most of my animations that used to work
on windows() version 2.11.1 and earlier now flash
as if the double buffering is turned off or buffer swapping
is triggered by other events than in the past.

The simplified example below using symbols
should illustrate the problem in a windows environment.

windows()

radius- 8
n- 6
ang- seq(0,2*pi,length=n+1)[-(n+1)]
ca- cos(ang)
sa- sin(ang)
size- c(.1, .3, .5, .7, .9, 1)

colors-  rainbow(length(size))

for (i in 1:1000){
radius- radius*.998
bnd- (radius+1)* c(-1, 1)
cenX- radius*ca
cenY- radius*sa
symbols(cenX, cenY, circles = size,
xlim=bnd, ylim=bnd, bg=colors)
}

I have not isolated the version  when the flashing
started but it somewhere between
2.11.1 and 2.14.1.

I did some searching on double-buffering
problems in R but didn't find indications
of this particular problem.

Slowing the animation down did not help.


I don't think there was ever a guarantee that double buffering would be 
sufficient for what you were doing:  you just got lucky.


What you need to do (and this should work, at least on the windows() device 
and some others), is use dev.hold() to stop redrawing, and dev.flush() when 
you are ready to display the new stuff.  Your loop becomes something like 
this:


for (i in 1:1000){
  dev.hold()
  radius - radius*.998
  bnd - (radius+1)* c(-1, 1)
  cenX - radius*ca
  cenY - radius*sa
  symbols(cenX, cenY, circles = size,
  xlim=bnd, ylim=bnd, bg=colors)
  dev.flush()
}

The dev.hold() function was introduced in 2.14.0.  I think dev.flush() 
existed earlier, but not for all systems.


Duncan Murdoch

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



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Assessing interaction effects in GLMMs

2012-05-26 Thread Luke Duncan
Dear R gurus

I am running a GLMM that looks at whether chimpanzees spend time in shade
more than sun (response variable 'y': used cbind() on counts in the sun and
shade) based on the time of day (Time) and the availability of shade
(Tertile). I've included some random factors too which are the chimpanzee
in question (Individual) and where they are in a given area (Zone). There
are also two continuous predictors (Minimum daily temperature: Min; Maximum
daily temperature: Max). I have run my GLMM and I know that Time and Min
are significant predictors of the patterns of shade use while Tertile and
Max are not. In addition, a Time*Tertile interaction effect is a good
predictor as well.

I now need to assess how the specific interaction effect conditions differ
to one another. So, for example, how does shade use differ between 10h00 at
low shade and 10h00 at high shade? I tried using the package multcomp, but
that will only allow me to work out the contrasts for the first-order
effects (Time, Tertile) but won't allow me to do so for the interaction
effects. Any ideas?

My code:

 m1 - lmer(y ~ Time*Tertile + (1|Individual) + (1|Zone) + Max +
Min,family=binomial,REML=F)
 Anova(m1,type=3,test=Wald)
Analysis of Deviance Table (Type III tests)

Response: y
   Chisq Df Pr(Chisq)
(Intercept)   0.9511  1 0.3294
Time 60.7807  4  1.988e-12 ***
Tertile   0.3391  1 0.5603
Max   1.3198  1 0.2506
Min  77.7736  1   2.2e-16 ***
Time:Tertile 38.9038  4  7.292e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 summary(m1)
Generalized linear mixed model fit by the Laplace approximation
Formula: y ~ Time * Tertile + (1 | Individual) + (1 | Zone) + Max + Min
  AIC  BIC logLik deviance
 1168 1224 -569.9 1140
Random effects:
 Groups NameVariance Std.Dev.
 Zone   (Intercept) 0.81949  0.90526
 Individual (Intercept) 0.36417  0.60347
Number of obs: 412, groups: Zone, 8; Individual, 7

Fixed effects:
 Estimate Std. Error z value Pr(|z|)
(Intercept)   0.774980.79465   0.975 0.329439
Time11h00-1.542590.24351  -6.335 2.38e-10 ***
Time12h00 0.016950.77829   0.022 0.982627
Time13h00-4.269130.78217  -5.458 4.81e-08 ***
Time14h00-1.345030.43831  -3.069 0.002150 **
TertileLow0.326140.56003   0.582 0.560323
Max   0.037510.03265   1.149 0.250630
Min  -0.309120.03505  -8.819   2e-16 ***
Time11h00:TertileLow  1.030790.28579   3.607 0.000310 ***
Time12h00:TertileLow -2.261870.79930  -2.830 0.004658 **
Time13h00:TertileLow  2.381290.79214   3.006 0.002646 **
Time14h00:TertileLow  1.722630.49397   3.487 0.000488 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
(Intr) Tm1100 Tm1200 Tm1300 Tm1400 TrtlLw MaxMinT1100:
Time11h00   -0.026
Time12h00   -0.035  0.177
Time13h00   -0.004  0.223  0.068
Time14h00   -0.073  0.259  0.081  0.103
TertileLow  -0.450  0.153  0.043  0.051  0.097
Max -0.711 -0.169 -0.004 -0.061 -0.023  0.019
Min  0.146  0.186  0.014  0.055  0.099 -0.036 -0.455
Tm11h00:TrL  0.059 -0.851 -0.153 -0.190 -0.222 -0.198  0.096 -0.155
Tm12h00:TrL  0.095 -0.160 -0.974 -0.062 -0.081 -0.067 -0.079  0.012  0.192
Tm13h00:TrL  0.026 -0.208 -0.067 -0.983 -0.099 -0.075  0.024 -0.026  0.229
Tm14h00:TrL  0.126 -0.215 -0.069 -0.088 -0.876 -0.185 -0.047  0.006  0.254
T1200: T1300:
Time11h00
Time12h00
Time13h00
Time14h00
TertileLow
Max
Min
Tm11h00:TrL
Tm12h00:TrL
Tm13h00:TrL  0.081
Tm14h00:TrL  0.098  0.116

Luke Duncan

*Post-doctoral** Fellow*
*School of Animal, Plant and Environmental Sciences*
*University of the Witwatersrand*
*Johannesburg, South Africa*
**
*+27 72 312 0330*
*+27 11 717 6452*

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 remove the 'promise' attribute of an R object (.Random.seed)?

2012-05-22 Thread luke-tierney

On Tue, 22 May 2012, Yihui Xie wrote:


Hi,

The problem arises when I lazyLoad() the .Random.seed from a
previously saved database. To simplify the process of reproducing the
problem, see the example below:

## this assignment may not really make sense, but illustrates the problem
delayedAssign('.Random.seed', 1L)

typeof(.Random.seed)
# [1] integer

rnorm(1)
# Error in rnorm(1) :
#  .Random.seed is not an integer vector but of type 'promise'

typeof(.Random.seed)
# [1] integer

So there must be an attribute promise somewhere attached to
.Random.seed, and I cannot find it. The R function typeof() does not
reveal it, but the TYPEOF() function in src/main/RNG.c says it is a
'promise'.

My question is, how to make R use the real value of .Random.seed
instead of complaining about the promise? Thanks!


Siple answer: Don't creat the promise in the first place, i.e. don't
use delayedAssign.

What is the real context where this arises? Knowing that may help us
decide whether the internals should address this possibility.

Best,

luke



Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA

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



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 remove the 'promise' attribute of an R object (.Random.seed)?

2012-05-22 Thread luke-tierney

I believe it would be better if the internal code forced the promise
at this point.  I'll have a look; there may be a few other similar
instances worth looking at.

luke

On Tue, 22 May 2012, Yihui Xie wrote:


Thanks! That is exactly what I did
(https://github.com/yihui/knitr/blob/master/R/cache.R#L44) but I was
wondering if .Random.seed could be better recognized when it is lazy
loaded.

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Tue, May 22, 2012 at 8:08 PM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:


You can remove it by a simple assignment:

.Random.seed - .Random.seed

will do it.  (The reason is that it doesn't copy the object blindly, it
evaluates the RHS to get 1L, and it's a regular assignment, so that gets put
into the LHS.)

Duncan Murdoch


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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
https://stat.ethz.ch/mailman/listinfo/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] Solve an ordinary or generalized eigenvalue problem in R?

2012-04-21 Thread Luke Hartigan
Hi all,

In my experience, using eigen to solve generalized eigenvalue / eigenvector
problems only gives correct looking eigenvalues while the eigenvectors seem
to be wrong (in comparison to results from MATLAB's 'eig' function for
example).

However, I think it is possible to solve generalized eigenvalue /
eigenvectors problems in R. The way I found that works in my case is to use
the simultaneous diagonalization method which is effectively two
applications of the 'svd' function.

I have used this myself to get results effectively the same (down to 6th
decimal place for example) as those from MATLAB.

Kind regards,
Luke

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] enableJIT(2) causes major slow-up in rpart

2012-04-13 Thread luke-tierney

The level 2 is a heuristic meant to help with certain kinds of
programming idioms. It isn't always going to work.  In this case
trace(cmpfun) will show three functions being compiled each time
through. Not sure why -- I'll try to find out and see if it can be
avoided.

luke

On Thu, 12 Apr 2012, Tal Galili wrote:


Hello,

Due to exploration of the JIT capabilities offered through the {compiler}
package, I came by the fact that using enableJIT(2) can *slow* the rpart
function (from the {rpart} package) by a magnitude of about 10 times.

Here is an example code to run:

library(rpart)
require(compiler)

enableJIT(0) # just making sure that JIT is off # We could also use
enableJIT(1) and it would be fine
fo - function() {rpart(Kyphosis ~ Age + Number + Start, data=kyphosis)}
system.time(fo())
#   user  system elapsed
#  0   0   0   # this can also be 0.01 sometimes.

enableJIT(2)  # also happens for enableJIT(3)
system.time(fo())
#   user  system elapsed
#   0.120.000.12


Which brings me to my *questions*:
1) Is this a bug or a feature?
2) If this is a feature, what is causing it? (or put another way, can one
predict ahead of time the implications of using enableJIT(2) or
enableJIT(3) on his code?)


*Links*:
A post I recently wrote about my exploration of JIT -
www.r-statistics.com/2012/04/speed-up-your-r-code-using-a-just-in-time-jit-compiler/
The question asked on SO regarding the limitations of JIT:
http://stackoverflow.com/questions/10106736/possible-shortcomings-for-using-jit-with-r

Thanks,
Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--

[[alternative HTML version deleted]]

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



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] recover lost global function

2012-04-05 Thread luke-tierney

The compiler doesn't currently look beyond the first definition found
(the generated code does the right thing, but the compiler won't
optimize calls to functions masked by non-functions).  I'll look into
whether thechecking can be made to take this into account; it may be
more trouble than it is worth though.

luke

On Thu, 5 Apr 2012, Sam Steingold wrote:


* Duncan Murdoch zheqbpu.qha...@tznvy.pbz [2012-04-04 21:46:57 -0400]:

On 12-04-04 5:15 PM, Sam Steingold wrote:

* Duncan Murdochzheqbpu.qha...@tznvy.pbz  [2012-04-04 17:00:32 -0400]:

There's no warning when you mask a function with a non-function at top
level, and little need for one, because R does the right search based on
the fact that you're making a function call:


c

[1] 1

c(1,2)

[1] 1 2


why then am I getting these warnings from cmpfile?


You would have to tell me what you did before I could attempt to answer
that.


all - 1
cmpfile(foo.R)

where foo.R contains functions which call all()





Note: no visible global function definition for 'all'
Note: no visible global function definition for 'all'
Note: no visible global function definition for 'all'
Note: no visible global function definition for 'all'
Note: no visible global function definition for 'all'
Note: no visible global function definition for 'all'
Note: no visible global function definition for 'all'
Note: no visible global function definition for 'all'
Note: no visible global function definition for 'all'
Note: no visible global function definition for 'all'

I did overwrite all to a data frame, but it only appears in a funtion
position all(...) in the file being compiled.








--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 add grid lines at specific position to a plot?

2012-03-15 Thread Luke Miller
abline(h = 0) will do what you want. abline(h = c(0,1,2)) would draw
additional lines at y = 1 and y = 2. abline(v = 0) would draw a vertical
line at x = 0. All of these lines will be plotted on top of whatever you
plotted previously, so you may have to replot your points or lines so that
they're not obscured by the ablines.

On Thu, Mar 15, 2012 at 10:05 AM, Michael comtech@gmail.com wrote:

 How to add grid lines at specific position to a plot?

 Hi all,

 [Disclaimer: I have done extensive and intensive searching on Google and
 asked around but couldn't find a solution to this problem.
 Please help me instead of just pointing out how simple and stupid my
 question is. God bless good folks! Thanks!]

 This is a headache for me and I have been struggling with this for a while.

 With an existing plot, how can I add a horizontal grid line at vertical
 location 0 (just need 1 grid line)...

 I can certainly draw such a line myself using lines.

 However, that will impact my legends because that also counts as a line.
 But we wouldn't want a grid line to be counted as a line...

 Could anybody please help me?

 Thanks!

[[alternative HTML version deleted]]

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




-- 
___
Luke Miller
Postdoctoral Researcher
Hopkins Marine Station, Stanford University
120 Ocean View Blvd
Pacific Grove, CA 93950
831-655-6208

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] memory management

2012-02-29 Thread luke-tierney

On Wed, 29 Feb 2012, Sam Steingold wrote:


* Milan Bouchet-Valat anyvzv...@pyho.se [2012-02-29 18:18:50 +0100]:

I think you're simply hitting a (terrible) OS limitation. Linux is
very often not able to reclaim the memory R has used because it's
fragmented.  The OS can only get the pages back if nothing is above
them, and most of the time there is data after the object you
remove. I'm not able to give you a more precise explanation, but
that's apparently a known problem and that's hard to fix.


compacting garbage collector is our best friend!


Which R does not use because of the problems it would create for
external C/Fortran code on which R heavily relies.


--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 unzip files in R

2012-01-31 Thread Luke Miller
Try the bzfile() function instead of unz(). You'll find that you're
taken to the same help page for both of those functions.

?bzfile

On Tue, Jan 31, 2012 at 2:34 PM, ql16717 ql16...@gmail.com wrote:

 Hi,

 I have downloaded a bunch of bz2 files. I wonder if R will be able to
 unzip them in a batch mode or even one at a time?

 I was looking at the unz function. But it didn't work well. Say I have
 a bz2 file in H:/Temp/65502805_532.pair.bz2. Anyone has any
 suggestion?

 thanks
 John

  setwd(H:\\Temp\\)
  getwd()
 [1] H:/Temp
  fn-list.files(pattern=bz2, full.names=TRUE)
  fn
 [1] ./65502805_532.pair.bz2
  unz(description=fn, filename=65502805_532.pair, open=r)
 Error in unz(description = fn, filename = 65502805_532.pair, open = r) :
  cannot open the connection
 In addition: Warning message:
 In unz(description = fn, filename = 65502805_532.pair, open = r) :
  cannot open zip file './65502805_532.pair.bz2'

  sessionInfo()
 R version 2.14.0 (2011-10-31)
 Platform: i386-pc-mingw32/i386 (32-bit)

 locale:
 [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
 States.1252
 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
 [5] LC_TIME=English_United States.1252

 attached base packages:
 [1] stats     graphics  grDevices utils     datasets  methods   base

 other attached packages:
 [1] pdInfoBuilder_1.18.0 oligo_1.18.1         oligoClasses_1.16.0
 affxparser_1.26.2    RSQLite_0.10.0
 [6] DBI_0.2-5            Biobase_2.12.1

 loaded via a namespace (and not attached):
 [1] affyio_1.22.0         Biostrings_2.22.0     bit_1.1-8
 ff_2.2-4              IRanges_1.12.1
 [6] preprocessCore_1.16.0 splines_2.14.0        tools_2.14.0
 zlibbioc_1.0.0

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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
https://stat.ethz.ch/mailman/listinfo/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] Incorrect DateTime using ISOdatetime in R

2012-01-20 Thread Luke Miller
666.1751 sure seems like it should return 2010-10-29 04:12:09 based on
your example.

666.1751 days from 2009-01-01 is 2010-10-29 + some hours/min/seconds.

0.1751 days * 24 hrs/day = 4.2024 (i.e. 4:00AM + some minutes).

0.2024 hours * 60 min/hr = 12.144 (i.e. 12 minutes + some seconds).

0.144 minutes * 60 sec/min = 8.64 (i.e. 8.64 seconds).

Put it all together and I get 2010-10-29 04:12:08.64 in the GMT time zone.

What makes you think it should be 2010-10-29 06:12:09? Are you running
into a time zone issue, such as your GPS adjusting its time zone and
reported the time based on the time zone where a reading was taken? If
you crossed between time zones for some of your readings it might
explain the fluctuating difference between the answer you expect and
the answer that ISOdatetime gives you.

-Luke


On Fri, Jan 20, 2012 at 6:59 AM, Sula2011 julia.so...@gmx.de wrote:

 Dear list,

 I need to transform the DateTime of my GPS data from:

 666.1751 into /mm/dd hh:mm:ss

 I have the following code:

 d$Date - ISOdatetime(2009, 1, 1, 0, 0, 0, tz = GMT)+d$Date*(24*3600)

 This gives me: 2010-10-29 04:12:09, which is wrong. It should be 2010-10-29
 06:12:09

 Another example:

 418.3219 corresponds to: 2010-02-23 07:43:30, but it should be 2010-02-23
 08:43:30.

 However, not always is the difference + 2 h, it's sometimes less or more.

 There are a lot of postings here regarding ISOdatetime, but I'm still not
 able to solve this . Any ideas or suggestions will be very much appreciated.

 Best regards,

 Julia

 PS. I've tried to find the answer in all sorts of R help forums and also in
 my R books - no luck so far. Maybe I'm missunderstanding the entire
 ISOdatetime function?

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Incorrect-DateTime-using-ISOdatetime-in-R-tp4313470p4313470.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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
https://stat.ethz.ch/mailman/listinfo/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] Incorrect DateTime using ISOdatetime in R

2012-01-20 Thread Luke Miller
You're running into time zone issues. If you're in a time zone that
recognizes daylight savings time for part of the year, the difference
in the value you calculate and the expected answer will vary.

Check your current system timezone:

Sys.timezone()

If it doesn't return UTC (aka GMT), you're going to run into issues.

For instance, if I set my system timezone to CET (for Germany), I can
recreate your problem.

Sys.setenv(TZ = CET)

 myTime = as.POSIXct(strptime('2010-10-29 6:12:09', format = '%Y-%m-%d 
 %H:%M:%S'))
 myTime
[1] 2010-10-29 06:12:09 CEST

 myTime2 = (unclass(myTime) - (unclass(ISOdatetime(2009,1,1,0,0,0, tz = 
 GMT / (24*3600)
 myTime2
[1] 666.1751
attr(,tzone)
[1] CET

 myTime3 = ISOdatetime(2009,1,1,0,0,0, tz = GMT) + (myTime2*24*3600)
Warning message:
In check_tzones(e1, e2) : 'tzone' attributes are inconsistent
 myTime3
[1] 2010-10-29 04:12:09 GMT

Note that 'myTime' was created in the CEST timezone. However, myTime2
is created by subtracting
myTime from an ISOdatetime set in the GMT timezone, resulting in the
666.1751 value. That value is almost certainly incorrect for use in
your first pass analysis. When I then try to convert myTime2 back into
a human-readable format, myTime3, the returned value is off by 2
hours, as you've found.

If you change the tz option in the ISOdatetime function to CET, you
should get the correct values back out. For example:

 myTime4 = (unclass(myTime) - (unclass(ISOdatetime(2009,1,1,0,0,0, tz = 
 CET / (24*3600)
 myTime4
[1] 666.2168
attr(,tzone)
[1] CET

 myTime5 = ISOdatetime(2009,1,1,0,0,0, tz = CET) + (myTime4*24*3600)
 myTime5
[1] 2010-10-29 06:12:09 CEST

When I keep everything in CET/CEST timezone with myTime4 and myTime5,
I get back the correct 6:12:09 time stamp.

However, if you intend to only be working on time stamps that are in
the GMT/UTC time zone, then the easiest solution may be to set your
system timezone (for the current R session) to UTC:

Sys.setenv(TZ='UTC')   # This is only active for the current R session

After doing that, I can great a time stamp, without an explicit time
zone, and R automatically sticks it into the UTC time zone.

 myTime6 = as.POSIXct(strptime('2010-10-29 6:12:09', format = '%Y-%m-%d 
 %H:%M:%S'))
 myTime6
[1] 2010-10-29 06:12:09 UTC

 myTime7 = (unclass(myTime6) - (unclass(ISOdatetime(2009,1,1,0,0,0, tz 
 =UTC / (24*3600)
 myTime7
[1] 666.2584
attr(,tzone)
[1] UTC

 myTime8 = ISOdatetime(2009,1,1,0,0,0, tz = UTC) + (myTime7*24*3600)
 myTime8
[1] 2010-10-29 06:12:09 UTC

That should cure your problems. You should re-run all of your FPT
analyses, since you may have been feeding them incorrect time values
all along.

-Luke




On Fri, Jan 20, 2012 at 11:24 AM, Julia Sommerfeld julia.so...@gmx.de wrote:
 Hi Luke,

 Thank you for the answer.

 On 20/01/2012, at 6:11 , Luke Miller wrote:

 666.1751 sure seems like it should return 2010-10-29 04:12:09 based on
 your example.

 666.1751 days from 2009-01-01 is 2010-10-29 + some hours/min/seconds.

 0.1751 days * 24 hrs/day = 4.2024 (i.e. 4:00AM + some minutes).

 0.2024 hours * 60 min/hr = 12.144 (i.e. 12 minutes + some seconds).

 0.144 minutes * 60 sec/min = 8.64 (i.e. 8.64 seconds).

 Put it all together and I get 2010-10-29 04:12:08.64 in the GMT time zone.

 What makes you think it should be 2010-10-29 06:12:09?


 The first fix of the original GPS data is at 06:12:09. So maybe the error is
 somewhere else?

 I'm calculating first passage time in R. To run FPT we had to transform
 DateTime.

 1.
 #paste Date and Time into one column DateTime
 DT-paste(GPS$Date, GPS$Time, sep= )

 GPS$DateTime-as.POSIXct(strptime(as.character(DT), %d/%m/%Y %H:%M:%S))

 #paste it together so that it is in the right format for FPT analysis
 loc - GPS[GPS$Bird==bird,c(LON, LAT, DateTime, Bird)]
 colnames(loc) - c(Long, Lat, gmt, bird)

 2. ##put date in format that FPT likes
 loc$Date - (unclass(loc$gmt) - unclass(ISOdatetime(2009, 1, 1, 0, 0, 0, tz
 = GMT)))/(24*3600)

 3. After running FPT, the date time needs to be transformed back
 from 666.1751 into /mm/dd hh:mm:ss

 And I used this function:

 d$Date - ISOdatetime(2009, 1, 1, 0, 0, 0, tz = GMT)+d$Date*(24*3600)

 where d is the FPT output file (previously loc).

 THANKS, Julia



 Are you running
 into a time zone issue, such as your GPS adjusting its time zone and
 reported the time based on the time zone where a reading was taken? If
 you crossed between time zones for some of your readings it might
 explain the fluctuating difference between the answer you expect and
 the answer that ISOdatetime gives you.

 -Luke


 On Fri, Jan 20, 2012 at 6:59 AM, Sula2011 julia.so...@gmx.de wrote:


 Dear list,


 I need to transform the DateTime of my GPS data from:


 666.1751 into /mm/dd hh:mm:ss


 I have the following code:


 d$Date - ISOdatetime(2009, 1, 1, 0, 0, 0, tz = GMT)+d$Date*(24*3600)


 This gives me: 2010-10-29 04:12:09, which is wrong. It should be 2010-10-29

 06:12:09


 Another example

Re: [R] using StatEt IDE for Eclipse

2011-12-06 Thread Luke Miller
)
 at
 org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:241)
  at
 org.eclipse.ui.menus.CommandContributionItem.handleWidgetSelection(CommandContributionItem.java:829)
 at
 org.eclipse.ui.menus.CommandContributionItem.access$19(CommandContributionItem.java:815)
  at
 org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(CommandContributionItem.java:805)
 at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
  at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
 at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
  at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
 at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
  at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
 at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
  at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
 at
 org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
  at
 org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
 at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
  at
 org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
 at
 org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
  at
 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
 at
 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
  at
 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
 at
 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
  at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
 at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
  at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
 at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
 !SUBENTRY 1 de.walware.statet.nico.ui 4 -1 2011-12-05 16:25:02.175
 !MESSAGE No session of R is active in the current workbench window.

 !ENTRY de.walware.statet.r.ui 4 20100 2011-12-05 16:25:02.666
 !MESSAGE An error occurred while submitting command to R.
 !STACK 1
 org.eclipse.core.runtime.CoreException: No session of R is active in the
 current workbench window.
 at de.walware.statet.nico.ui.NicoUITools.accessTool(NicoUITools.java:137)
  at
 de.walware.statet.nico.ui.NicoUITools.accessController(NicoUITools.java:178)
 at
 de.walware.statet.nico.ui.NicoUITools.accessController(NicoUITools.java:166)
  at
 de.walware.statet.r.internal.debug.ui.RControllerCodeLaunchConnector.submit(RControllerCodeLaunchConnector.java:68)
 at
 de.walware.statet.r.launching.RCodeLaunching.runRCodeDirect(RCodeLaunching.java:430)
  at
 de.walware.statet.r.internal.debug.ui.launcher.RunEntireCommandHandler.doLaunch(RunEntireCommandHandler.java:179)
 at
 de.walware.statet.r.internal.debug.ui.launcher.RunEntireCommandHandler$1.run(RunEntireCommandHandler.java:107)
  at
 org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
 !SUBENTRY 1 de.walware.statet.nico.ui 4 -1 2011-12-05 16:25:02.667
 !MESSAGE No session of R is active in the current workbench window.

 !ENTRY de.walware.statet.r.console.ui 1 0 2011-12-05 16:27:22.157
 !MESSAGE Launching the R Console was cancelled, because it seems starting
 the R engine failed.
 Please make sure that R package 'rj' (1.0.0 or compatible) is installed and
 that the R library paths are set correctly for the R environment
 configuration 'R-2.14.0'.

        [[alternative HTML version deleted]]

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




--
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 endnote entry

2011-11-30 Thread Luke Miller
I have R entered as a computer program, and in the Programmer Name field
I write it as:

R Development Core Team,

Notice the comma after Team. That seems to be the key to getting Endnote to
treat the whole thing as a surname that doesn't get abbreviated.

On Wed, Nov 30, 2011 at 10:56 PM, Matt Cooper mattcst...@gmail.com wrote:

 I know citation() gives the R citation to be used in publications. Has
 anyone put this into endnote nicely? I'm not very experienced with
 endnote, and the way I have it at the momeny the 'R Development Core
 Team' becomes R. D. C. T. etc.

 Cheers.

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




-- 
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Weird R's behaviour with a quoted name

2011-11-21 Thread luke-tierney

On Mon, 21 Nov 2011, William Dunlap wrote:


This is a bug in R: it either should prohibit the
attaching of attributes to things of class name
or should make it so that attachment of an attribute
doesn't have such a global effect.

A more direct example of the problem is:
  attributes(quote(some.name))
 NULL
  bar - structure(quote(some.name), someAttribute=someAttribute's value)
  attributes(quote(some.name))
 $someAttribute
 [1] someAttribute's value

I reported a similar problem to R-devel in March of
2010 under the subject line symbol name caching bug:
attributes get tied to symbol names.  The consensus
then seemed to be that prohibiting attributes on things
of class name was the way to go.


Yes -- just hasn't risen high enough on anyone's todo list to get done.

Best,

luke



Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Kamil Barton
Sent: Monday, November 21, 2011 8:31 AM
To: r-help@r-project.org
Subject: [R] Weird R's behaviour with a quoted name

Can someone explain why the following happens?
---
: quote(some.name)
some.name
: bar - structure(quote(some.name), class = foo)
: quote(some.name)
Error in print(some.name) : object 'some.name' not found
: bar - quote(some.name)
: quote(some.name)
Error in print(some.name) : object 'some.name' not found
: bar - as.name(some.name)
: quote(some.name)
some.name
---

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Specifying Greek Character in Lattice Plot Label

2011-10-21 Thread Luke Miller
The following produces something very similar to David's method:

plot(1,1, xlab = expression(paste(Conductivity (, mu, S / cm

but with a slightly different slash character. I think David's method
is more correct, but I've used the above method in the past with
some success.

On Fri, Oct 21, 2011 at 11:45 AM, David Winsemius
dwinsem...@comcast.net wrote:

 On Oct 21, 2011, at 11:27 AM, Rich Shepard wrote:

  For an axis label I want to include the Greek letter mu within the string.
 I've not found the proper way of including that expression within the
 string.

  What I want is Conductivity (uS/cm) with the 'u' replaced by mu. When I
 try Conductivity ( expression(paste(mu)) S/cm) I get an error. If I
 don't separate Conductivity and S/cm with parentheses the string
 'expression(paste(mu))' displays in the lable.

 try:

  plot(1,1, xlab=expression(Conductivity~(*mu*S/cm*)) )

 Parens are the only characters that need to be quoted and you do need to use 
 proper plotmath connectors,  ~ and * depending on whether you ant a space 
 to appear or not. I don't hink you can join character values and expression 
 values in the manner that you offer but I admit I never tried it, so I don't 
 know for sure. Generally language and expression objects have their own 
 special set of functions and syntax.


  What am I doing incorrectly?

 Rich

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

 David Winsemius, MD
 West Hartford, CT

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



--
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 wav file into R

2011-10-15 Thread Luke Miller
Try the tuneR package. It will read in wav files and has other functions for
manipulating sound data.
 On Oct 15, 2011 9:32 PM, Noah Silverman noahsilver...@ucla.edu wrote:

 Hi,

 I'm interested in doing some sound analysis with R.

 Does anyone have any experience/methods for reading in a wav file?

 --
 Noah Silverman
 UCLA Department of Statistics
 8208 Math Sciences Building
 Los Angeles, CA 90095


[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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
https://stat.ethz.ch/mailman/listinfo/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 adjust the y-axis range in barplot properly

2011-09-22 Thread Luke Miller
This should do the trick:

barplot(data, ylim=c(60,90), beside=TRUE, xpd = FALSE)

As usual, check ?barplot first for clues on how to customize the plot
to your specifications.

On Thu, Sep 22, 2011 at 11:49 AM, Benedikt Drosse dro...@mpipz.mpg.de wrote:

 Hello R-Users,
 it might be a rather simple problem I have, but I couldn't find any solution 
 online. Thus, here is my problem:

 I would like to adjust the y-axis range in a barplot, since all my values are 
 70. Therefore I would like to only visualize the y-axis from 60-100 (example 
 1).
 The problem is, the range of the y-axis is adjusted, but the barsize stays 
 the same and vanishes from the plot area.
 How can I cut the y-axis and the bars in a proper way. Unfortunatlely I dit 
 not get gap.barplot function to work on the matrix in example 1.

 I would be very greatful for some ideas and help,
 cheers,
 Benedikt

 example 1:
 data - as.matrix(rbind(c(85:90), c(75:80)))
 barplot(data, beside=TRUE)
 barplot(data, ylim=c(60,90), beside=TRUE)

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



--
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 writing basic loop

2011-09-16 Thread Luke Miller
Create an output vector to hold your slopes before starting the loop, then
use your index i to place each new slope in the appropriate position in your
vector.

y1-rnorm(100, mean=0.01, sd=0.001)
y2-rnorm(100, mean=0.1, sd=0.01)

x-(c(10,400))

my.slopes = vector(numeric,100)  #  initialize a numeric vector, length
100, filled with zeros initially

for (i in 1:100) {

#create the linear model for each data set
model1-lm(c(y1[i],y2[i])~x)
slope1-model1$coefficients[2]
my.slopes[i] = slope1 #  stick each new slope value into my.slopes[i]
}

You could skip the slope1 - model1$coefficients[2]  step and just put the
slope directly into my.slopes[i] as well.

On Fri, Sep 16, 2011 at 3:25 PM, beaulieu.j...@epamail.epa.gov wrote:

 Hello,

 I would like to write a loop to 1) run 100 linear regressions, and 2)
 compile the slopes of all regression into one vector.  Sample input data
 are:

 y1-rnorm(100, mean=0.01, sd=0.001)
 y2-rnorm(100, mean=0.1, sd=0.01)

 x-(c(10,400))

 #I have gotten this far with the loop

 for (i in 1:100) {

 #create the linear model for each data set
 model1-lm(c(y1[i],y2[i])~x)
 slope1-model1$coefficients[2]
 }

 How can I compile the slopes from all 100 regressions into one vector?

 Thanks,
 Jake
[[alternative HTML version deleted]]

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




-- 
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 subsetting data based on date AND time

2011-09-08 Thread Luke Miller
Try altering your subset operation from this:

with(DataSet, subset(DataSet, DataSet$NewDateTime  '2004-08-05 14:15:00'))

to this:

with(DataSet, subset(DataSet, DataSet$NewDateTime  as.POSIXct('2004-08-05
14:15:00')))

and see if you get the desired effect.

The statement DataSet$NewDateTime  '2004-08-05 14:15:00' is asking R to
find all of the rows in DataSet$NewDateTime that are less than the
*character* value '2004-08-05 14:15:00'. You need to convert that
*character* value to a POSIX time value first, using as.POSIXct(). Then you
can successfully carry out the comparison between the POSIXct values in
DataSet$NewDateTime and your newly created POSIX time value.

Because your character time value is listed in the standard POSIX format
(-mm-dd HH:MM:SS), you don't need to include the format information
(%y-%m-%d %H:%M:%S) in the as.POSIXct() function, which saves a little
typing. If it was in another format (mm-dd-) you'd need to use the
format argument in as.POSIXct() to make the character-to-POSIXct conversion
correctly.


On Thu, Sep 8, 2011 at 4:03 PM, Steve E. se...@vt.edu wrote:

 Dear R Community,

 I am new to R, and have a question that I suspect may be quite simple but
 is
 proving a formidable roadblock for me.  I have a large data set that
 includes water-quality measurements collected over many 24-hour periods.
 The date and time of sample collection are in a combined Date/Time field in
 the format -mm-dd hh:mm:ss.  I need to be able to subset the data for
 analysis of different date and time windows.  Thus far, I have tried
 casting
 the Date/Time field using several approaches, such as:

 DataSet$NewDateTime - strptime(DataSet$DateTime, '%Y-%m-%d %H:%M:%S')
 DataSet$NewDateTime - as.POSIXlt(strptime(DataSet$DateTime, '%Y-%m-%d
 %H:%M:S'))

 These instructions seem to cast the NewDateTime field correctly (at least
 it
 appears to be in the correct format, and I assume R sees the field as a
 date
 and a time) but I am then unable to subset the data using instructions such
 as:

 with(DataSet, subset(DataSet, DataSet$NewDateTime  '2004-08-05 14:15:00'))
 DataSubset - subset(DataSet, DataSet$NewDateTime  '2004-08-05 14:00:00',
 select = DataSet)

 I have tried also separating the date and time fields in the input file,
 and
 casting with instructions such as:

 DataSet$NewTime - strptime(DataSet$Time, '%H:%M:%S')
 DataSet$NewTime - as.POSIXct(strptime(DataSet$Time, '%H:%M:%S'))

 but these seem to generate a NewTime field that contains today's date + the
 time data, and also will not subset based on date/time.

 I appreciate greatly any help and advice,
 Steve

 --
 View this message in context:
 http://r.789695.n4.nabble.com/help-subsetting-data-based-on-date-AND-time-tp3799933p3799933.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

[[alternative HTML version deleted]]

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


Re: [R] Help with creating date as POSIXct

2011-09-01 Thread Luke Miller
This should be due to the fact that 110809 60 0 is not interpreted as a
valid time value.

You probably want to have

time.t - 0:3599

rather than time.t - 1:3600 if you want one value for each second in the
hour, starting from 00:00:00 and running to 00:59:59. 00:60:00 is not a
proper time value.

On Thu, Sep 1, 2011 at 7:18 AM, J. Augusiak jaugus...@googlemail.comwrote:

 Dear list,



 I want to create a POSIX time vector as follows:



 day- as.character(110809)

 time.t - 1:3600

 t.min  - time.t %/% 60

 t.sec  - time.t-t.min*60

 DATE   - as.POSIXct(strptime(paste(day,t.min,t.sec),%y%m%d %M%S))

 Tail(DATE)





 The problem is that the last element (3600) returns a NA and I don't
 understand why. 600, 1200, 2400 no problem, only 3600. Any helpful advice
 is
 highly appreciated :)



 Cheers,



 Jacqueline






[[alternative HTML version deleted]]

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




-- 
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Getting vastly different results when running GLMs

2011-08-17 Thread Luke Duncan
 into the model influences which factors are significant and
which are not. Why is this the case? Am I doing something wrong here with my
data structure or coding? For example, if I switch the order from
'behav*loc' to 'loc*behav' I get yet another set of results that match
neither the first R GLM results, nor the original results from the other
program.

I have checked the model for overdispersion and found that it is not
overdispersed. What am I doing wrong here? How can the same dataset be
generating such vastly different outcomes? I suspect that it may lie in the
way in which the model is fitted (R does iteratively reweighted least
squares whereas, Statistica may use something entirely different; what
exactly, I have no clue...) but I am none the wiser in this regard, so I
really don't know.

Regards, in despiration...

Luke

*PhD Candidate*
*School of Animal, Plant and Environmental Sciences*
*University of the Witwatersrand*
*Johannesburg, South Africa*

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] How do you report lmer results?

2011-07-26 Thread Luke Duncan
.

Sincerely (in desperation)

Luke Duncan

PhD Candidate
School of Animal, Plant and Environmental Sciences
University of the Witwatersrand
Johannesburg, South Africa

+27 11 717 6452

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Is there an R program that produces optimal solution/mix of multiple samples' varying volumes and values

2011-07-25 Thread luke
Sorry about the lengthy subject line.
Anyone know of an R' program that can look at several sources' varying
available volumes/amounts and their individual set of values, compared
to a target range/curve for these values, to find the optimal
mixture(s) of these possible sources for the desired curve, and for a
specified amount? I hope that makes sense as a reader.

Thanks for your time.
Luke

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Question about output from twitteR package

2011-07-23 Thread Doug Luke
Dear R-List,

I am trying to develop a tutorial on how to analyze network data from Twitter 
conversations for a network analysis class that I teach. I came across the 
twitteR package, and saw some examples of it in action on various websites. It 
is easy to use, and almost as easy to understand. I was able to pull sets of 
Twitter messages into a dataframe using various criteria (hashtags, etc.). To 
build a network, I would like to follow which messages are responses to earlier 
messages. According to the twitteR package documentation, this is stored in a 
'replyToSN' field (reply to Screenname). However, when I do searches this field 
is always blank (NA). (The similar field replyToSID is also always blank.) The 
Twitter messages themselves suggest that there are some replies in the sets 
that I'm obtaining, so I now in theory that these fields should not be blank 
for every message.

Here is some code and output to make this clearer:

library(twitteR)
library(plyr)
tweets = searchTwitter(#Rstats, n=200)
tweets[[4]]$getText()

[1] RT @kdnuggets: Great post on using parallel processing with R and HHP $3M 
competition http://bit.ly/rcfztQ #rstats #hhp #datamining

tweets[[4]]$getScreenName()

[1] dichika

tweets[[4]]$getReplyToSN()
character(0)

tweets.df = ldply(tweets, function(t) t$toDataFrame())
head(tweets.df[,c(3,4,6,10)])


  replyToSN created replyToSIDscreenName
1NA 2011-07-23 01:56:46 NAcmprsk
2NA 2011-07-23 01:38:58 NA  muteokie
3NA 2011-07-23 00:27:32 NA floss4science
4NA 2011-07-23 00:16:06 NA   dichika
5NA 2011-07-22 22:20:55 NAcmprsk
6NA 2011-07-22 21:50:43 NA  siah

I hope I'm missing something simple, but my gut tells me that I need to do some 
type of authentification before this information will be returned. I couldn't 
find any useful examples of this issue or how to get around it after looking 
for a while.

Thanks,

Douglas Luke

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


Re: [R] strange date problem - May 3, 1992 is NA

2011-06-22 Thread Luke Miller
For what it's worth, I cannot reproduce this problem under a nearly
identical instance of R (R 2.12.1, Win 7 Pro 64-bit). I also can't
reproduce the problem with R 2.13.0. You've got something truly weird
going on with your particular instance of R.


 is.na(strptime(5/3/1992, format=%m/%d/%Y))
[1] FALSE
 is.na(strptime(5/2/1992, format=%m/%d/%Y))
[1] FALSE
 sessionInfo()
R version 2.12.1 (2010-12-16)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] rj_0.5.2-1  lattice_0.19-17

loaded via a namespace (and not attached):
[1] grid_2.12.1  rJava_0.8-8  tools_2.12.1


On Wed, Jun 22, 2011 at 2:40 PM, Alexander Shenkin ashen...@ufl.edu wrote:
 On 6/22/2011 1:34 PM, Sarah Goslee wrote:
 On Wed, Jun 22, 2011 at 2:28 PM, David Winsemius dwinsem...@comcast.net 
 wrote:

 On Jun 22, 2011, at 2:03 PM, Sarah Goslee wrote:

 Hi,

 On Wed, Jun 22, 2011 at 11:40 AM, Alexander Shenkin ashen...@ufl.edu
 wrote:

 is.na(strptime(5/2/1992, format=%m/%d/%Y))

 [1] FALSE

 is.na(strptime(5/3/1992, format=%m/%d/%Y))

 [1] TRUE

 I can't reproduce your problem on R 2.13.0 on linux:

 I also cannot reproduce it on a Mac with 2.13.0 beta

 Which strongly suggests that you should start by upgrading your R
 installation if at all possible.

 I'd also recommend trying it on a default R session, with no extra
 packages loaded, and no items in your workspace. It's possible that
 something else is interfering.

 On linux, that's achieved by typing R --vanilla at the command line.
 I'm afraid I don't know how to do it for Windows, but should be
 similarly straightforward.

 Thanks Sarah.  Still getting the problem.  I should surely upgrade, but
 still, not a bad idea to get to the bottom of this, or at least have it
 documented as a known issue.  BTW, I'm on Windows 7 Pro x64.

 (running Rgui.exe --vanilla):

 is.na(strptime(5/3/1992, format=%m/%d/%Y))
 [1] TRUE

 is.na(strptime(5/2/1992, format=%m/%d/%Y))
 [1] FALSE

 sessionInfo()
 R version 2.12.1 (2010-12-16)
 Platform: i386-pc-mingw32/i386 (32-bit)

 locale:
 [1] LC_COLLATE=English_United States.1252
 [2] LC_CTYPE=English_United States.1252
 [3] LC_MONETARY=English_United States.1252
 [4] LC_NUMERIC=C
 [5] LC_TIME=English_United States.1252

 attached base packages:
 [1] stats     graphics  grDevices utils     datasets  methods   base

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




-- 
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Quick R syntax question

2011-06-20 Thread Luke Miller
If we assume that your data are in a data frame (which doesn't allow
spaces in column names, hence the periods in the call below):

df = data.frame(Major.Gleason = c(4,5,2,3), Minor.Gleason = c(3,2,4,3))

You can paste together the contents of the two columns with a plus
sign in between using the paste() function. The sep='' option at the
end of the function call specifies that no spaces should be included
between pasted items.

output = paste(as.character(df [,'Major.Gleason']), '+', as.character(df[ 
,'Minor.Gleason']), sep='')

The new object 'output' is a character vector containing the 4 strings
you're after:

 print(output)
[1] 4+3 5+2 2+4 3+3


On Mon, Jun 20, 2011 at 11:31 AM, Ben Ganzfried ben.ganzfr...@gmail.com wrote:

 Hi --

 I had a pretty quick R question since unfortunately I have not been able to
 find an answer on Google.  It shouldn't take much more than a minute to
 answer.

 I'm trying to add up the major gleason grade and minor gleason grade for an
 analysis of patients with prostate cancer.  One column has values under
 Major Gleason and another column has values under Minor Gleason.  For
 example,
 Major Gleason     Minor Gleason
 4                         3
 5                         2
 2                         4
 3                         3

 I want my output to be:
 4+3
 5+2
 2+4
 3+3

 The quasi-pseudocode in Java is basically:

 major = column$majorGleason
 minor = column$minorGleason
 for item in len(Major Gleason) {
  string s = major(item) + minor(item);
 }
 return s;

 But trying the same idea in R:

 string - major + minor

 gives me an error: unexpected string constant in...

 I would greatly appreciate any help.

 Thanks,

 Ben

        [[alternative HTML version deleted]]

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



--
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Quick R syntax question

2011-06-20 Thread Luke Miller
The quotes around 'Major.Gleason' and 'Minor.Gleason' are required for
accessing data frame columns by name. You could alternately refer to
the columns by number if you're sure you know which column is which:

 output = paste(df[ ,1], df[ ,2], sep = '+')

It's just a requirement for accessing things named with text strings
when using [ ] bracket notation. For instance, if you wanted to simply
print the contents of the 'Major.Gleason' column to your terminal, you
could do this:

 df[ ,'Major.Gleason']
[1] 4 5 2 3

or do it this way:

 df[ ,1]
[1] 4 5 2 3

As you can see, the quotes around Major/Minor Gleason don't really
have anything to do with the paste() function, they have everything to
do with extracting the desired data from the data frame column so that
paste() can go to work on the data.

On Mon, Jun 20, 2011 at 12:21 PM, Ben Ganzfried ben.ganzfr...@gmail.com wrote:
 Thanks!  Very glad you pointed me to the paste function, it looks very
 helpful.

 I have a quick follow-up after reading through the online tutorial on the
 paste function:

 Why do we need quotation marks around Major Gleason and Minor Gleason
 in: output = paste(df [,'Major.Gleason'],  df[ ,'Minor.Gleason'], sep='+')?
 The paste function is going to concatenate the first and second parameters
 and separate them by the + sign, so I'm not clear why we need to put
 quotation marks around the dataframe column headers...

 Thanks,

 Ben


 On Mon, Jun 20, 2011 at 11:58 AM, David Winsemius dwinsem...@comcast.net
 wrote:

 On Jun 20, 2011, at 11:47 AM, Luke Miller wrote:

 If we assume that your data are in a data frame (which doesn't allow
 spaces in column names, hence the periods in the call below):

 df = data.frame(Major.Gleason = c(4,5,2,3), Minor.Gleason = c(3,2,4,3))

 You can paste together the contents of the two columns with a plus
 sign in between using the paste() function. The sep='' option at the
 end of the function call specifies that no spaces should be included
 between pasted items.

 output = paste(as.character(df [,'Major.Gleason']), '+',
 as.character(df[ ,'Minor.Gleason']), sep='')

 I do not think the as.character is needed. Coercion to character is
 implicit in the use of paste(). And  the sep argument could be +.

 output = paste(df [,'Major.Gleason'],  df[ ,'Minor.Gleason'], sep='+')

 --
 David.


 The new object 'output' is a character vector containing the 4 strings
 you're after:

 print(output)

 [1] 4+3 5+2 2+4 3+3


 On Mon, Jun 20, 2011 at 11:31 AM, Ben Ganzfried ben.ganzfr...@gmail.com
 wrote:

 Hi --

 I had a pretty quick R question since unfortunately I have not been able
 to
 find an answer on Google.  It shouldn't take much more than a minute to
 answer.

 I'm trying to add up the major gleason grade and minor gleason grade for
 an
 analysis of patients with prostate cancer.  One column has values under
 Major Gleason and another column has values under Minor Gleason.
  For
 example,
 Major Gleason     Minor Gleason
 4                         3
 5                         2
 2                         4
 3                         3

 I want my output to be:
 4+3
 5+2
 2+4
 3+3

 The quasi-pseudocode in Java is basically:

 major = column$majorGleason
 minor = column$minorGleason
 for item in len(Major Gleason) {
  string s = major(item) + minor(item);
 }
 return s;

 But trying the same idea in R:

 string - major + minor

 gives me an error: unexpected string constant in...

 I would greatly appreciate any help.

 Thanks,

 Ben

       [[alternative HTML version deleted]]

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



 --
 ___
 Luke Miller
 Postdoctoral Researcher
 Marine Science Center
 Northeastern University
 Nahant, MA
 (781) 581-7370 x318

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

 David Winsemius, MD
 West Hartford, CT






-- 
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Snow/Snowfall hangs on windows 7

2011-05-16 Thread luke-tierney

Thanks to Thomas, Steve, Uwe, and others for reporting the problem and
suggesting fixes. A new version of snow is on its way to CRAN that
hopefully fixes the problem on Windows without breaking tings
elsewhere.  I don't have access to Windows at the moment so if things
don't work and you are willing to help debug then please let me know.
I was hoping to be able to make snow robust to spaces in paths on
other platforms as well but that seems to be complicated, so for now I
signal an error on non-Windows platforms with spaces in path names
snow uses. Also, I have not tested mpi or nws back ends on Linux.
Again, if this version creates problems for you and you are willing to
help sort things out please let me know.

This release also includes some experimental performance monitoring
tools described in ?snow.time.

Best,

luke

On Mon, 16 May 2011, Uwe Ligges wrote:


Folks,

I guess I know what is going on (and why I haven't seen this so far): All of 
you have installed R in a directory with blanks in it, right?


Please source() the attached sock.R and afterwards try again. Does it work 
with SOCK clusters now? Then it was just the lack of quotes.


CCing Luke the diffs (against snow 0.3-3 on CRAN):

@@ -29,8 +29,8 @@
env - paste(MASTER=, master,
  PORT=, port,
  OUT=, outfile,
-  SNOWLIB=, snowlib, sep=)
-cmd - paste(rscript, script, env)
+  SNOWLIB=, shQuote(snowlib), sep=)
+cmd - paste(shQuote(rscript), shQuote(script), env)
}
else {
script - RunSnowWorker RSOCKnode.R
@@ -43,13 +43,13 @@
else {
if (homogeneous) {
scriptdir - getClusterOption(scriptdir, options)
-script - file.path(scriptdir, RSOCKnode.sh)
+script - shQuote(file.path(scriptdir, RSOCKnode.sh))
rlibs - paste(getClusterOption(rlibs, options), collapse = 
:)

rprog - getClusterOption(rprog, options)
env - paste(MASTER=, master,
  PORT=, port,
  OUT=, outfile,
-  RPROG=, rprog,
+  RPROG=, shQuote(rprog),
  R_LIBS=, rlibs, sep=)
}
else {


(same problem in mpi.R, nws.R etc. as well, I think)

Best wishes,
Uwe









On 16.05.2011 00:01, David Anisman wrote:

Same problem as Anna here.

Windows 7 64-bit. Running R 2.13.0. snow + snowfall installed.

Testing:

library(snow)
library(snowfall)

sfInit(parallel=TRUE, cpus=2, type=SOCK)

Then R spins forever (yes, I disabled the Windows firewall).

On the same box, tried the same on Ubuntu under Virtualbox. No problem. 
Runs

well.

Any suggestions/ideas appreciated.


David



--
View this message in context: 
http://r.789695.n4.nabble.com/Snow-Snowfall-hangs-on-windows-7-tp3436724p3524990.html

Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.




--
Luke Tierney
Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:  l...@stat.uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] setting options only inside functions

2011-05-02 Thread luke-tierney

On Fri, 29 Apr 2011, William Dunlap wrote:


-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of
luke-tier...@uiowa.edu
Sent: Friday, April 29, 2011 9:35 AM
To: Jonathan Daily
Cc: r-help@r-project.org; Hadley Wickham; Barry Rowlingson
Subject: Re: [R] setting options only inside functions

The Python solution does not extend, at least not cleanly, to things
like dev on/ dev off or to Hadley's locale example.  In any case if I
am reading the Python source correctly on how they handle user
interrupts this solution has the same non-robusness to user interrupts
issue that Bill's initial solution had.

As a basis I believe what we need is a mechanism that handles a
setup, an action, and a cleanup, with setup and cleanup occurring with
interrupts disablednand the action with interrupts enabled. Scheme's
dynamic wind is similar, though I don't believe the scheme standard
addresses interrupts and we don't need to worry about continuations,
but some of the issues are similar.  Probably we would want two
flavors, one in which the action has to be a function that takes as a
single argument the result produced by the setup code, and one in
which the action can be an argument expression that is then evaluated
at the appropriate place by laze evaluation.

This can be done at the R level except for the controlling of
interrupts (and possibly other asynchronous stuff)-- that would need a
new pair of primitives (suspendInterrupts/enableInterupts or something
like that).  There is something in the Haskell literature on this that
I have looked at a while back -- probably time to have another look.


Luke,

 A similar problem is that if optionsList contains an illegal
option then setting options(optionList) will commit changes
to .Options as it works it way down the optionList until it
hits the illegal option, when it throws an error.  Then the
following on.exit is never called (it wouldn't have the output
of options(optionList) to work on if it were called) and the
initial settings in optionList stick around forever.  E.g.,

  withOptions - function(optionList, expr) {
 + oldOpt - options(optionList)
 + on.exit(options(oldOpt))
 + expr
 + }
  getOption(height)
 NULL
  getOption(width)
 [1] 80
  withOptions(list(height=10, width=-2), 666)
 Error in options(optionList) :
   invalid 'width' parameter, allowed 10...1
  getOption(height)
 [1] 10
  getOption(width)
 [1] 80

I haven't checked to see if par() works in the same way - it
does in S+.

An ignoreInterrupts(expr) function would not help in that case.


It would be solving an orthogonal problem.


Making options() (and par()) atomic operations would help, but that
may be a lot of work.


But it would be the right thing to do for this purpose, either by
creating an atomic version just for use in this context or by having a
withOptions construct recursively work thougheach option.


 options() might also warn but no change
.Options if there were an attempt to set an illegal option.


Seems more or less the same as making options() atomic.

Best,

luke



Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com




On Thu, 28 Apr 2011, Jonathan Daily wrote:


I would also love to see this implemented in R, as my

current solution

to the issue of doing tons of open/close, dev/dev.off, etc.

is to use

snippets in my IDE, and in the end I feel like it is a hack job. A
pythonic with function would also solve most of the

situations where

I have had to use awkward try or tryCatch calls. I would be

willing to

help with this project, even if it is just testing.

On Wed, Apr 27, 2011 at 5:43 PM, Barry Rowlingson
b.rowling...@lancaster.ac.uk wrote:

but it's a little clumsy, because

with_connection(file(myfile.txt), {do stuff...})

isn't very useful because you have no way to reference

the connection

that you're using. Ruby's blocks have arguments which

would require

big changes to R's syntax.  One option would to use pronouns:


 Looking very much like python 'with' statements:

http://effbot.org/zone/python-with-statement.htm

 Implemented via the 'with' statement which can operate on anything
that has a __enter__ and an __exit__ method. Very neat.

Barry

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.








--
Luke Tierney
Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
Actuarial Science
241 Schaeffer Hall  email:  l...@stat.uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu





--
Luke Tierney
Statistics and Actuarial Science
Ralph E. Wareham Professor

Re: [R] setting options only inside functions

2011-04-29 Thread luke-tierney

The Python solution does not extend, at least not cleanly, to things
like dev on/ dev off or to Hadley's locale example.  In any case if I
am reading the Python source correctly on how they handle user
interrupts this solution has the same non-robusness to user interrupts
issue that Bill's initial solution had.

As a basis I believe what we need is a mechanism that handles a
setup, an action, and a cleanup, with setup and cleanup occurring with
interrupts disablednand the action with interrupts enabled. Scheme's
dynamic wind is similar, though I don't believe the scheme standard
addresses interrupts and we don't need to worry about continuations,
but some of the issues are similar.  Probably we would want two
flavors, one in which the action has to be a function that takes as a
single argument the result produced by the setup code, and one in
which the action can be an argument expression that is then evaluated
at the appropriate place by laze evaluation.

This can be done at the R level except for the controlling of
interrupts (and possibly other asynchronous stuff)-- that would need a
new pair of primitives (suspendInterrupts/enableInterupts or something
like that).  There is something in the Haskell literature on this that
I have looked at a while back -- probably time to have another look.


On Thu, 28 Apr 2011, Jonathan Daily wrote:


I would also love to see this implemented in R, as my current solution
to the issue of doing tons of open/close, dev/dev.off, etc. is to use
snippets in my IDE, and in the end I feel like it is a hack job. A
pythonic with function would also solve most of the situations where
I have had to use awkward try or tryCatch calls. I would be willing to
help with this project, even if it is just testing.

On Wed, Apr 27, 2011 at 5:43 PM, Barry Rowlingson
b.rowling...@lancaster.ac.uk wrote:

but it's a little clumsy, because

with_connection(file(myfile.txt), {do stuff...})

isn't very useful because you have no way to reference the connection
that you're using. Ruby's blocks have arguments which would require
big changes to R's syntax.  One option would to use pronouns:


 Looking very much like python 'with' statements:

http://effbot.org/zone/python-with-statement.htm

 Implemented via the 'with' statement which can operate on anything
that has a __enter__ and an __exit__ method. Very neat.

Barry

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








--
Luke Tierney
Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:  l...@stat.uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] setting options only inside functions

2011-04-27 Thread luke-tierney

Put together a list and we can see what might make sense.  If we did
take this on it would be good to think about providing a reasonable
mechanism for addressing the small flaw in this function as it is
defined here.

Best,

luke

On Wed, 27 Apr 2011, Hadley Wickham wrote:


This has the side effect of ignoring errors
and even hiding the error messages.  If you
are concerned about multiple calls to on.exit()
in one function you could define a new function
like
 withOptions - function(optionList, expr) {
  oldOpts - options(optionList)
  on.exit(options(oldOpts))
  expr # lazily evaluate
 }


I wish R had more functions like this.  This sort of behaviour is also
useful when you open connections or change locales.  Ruby's blocks
provide nice syntactic sugar for this idea.

Hadley




--
Luke Tierney
Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:  l...@stat.uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 to .jpeg

2011-04-12 Thread Luke Miller
How about using paste() inside the jpeg() function to append a '.jpg' to the
end of your species name?
See the change below. I also added a dev.off() to close the newly created
jpeg.

species.name=CussoniaHolstii
dia-10:100
biomass = -21.4863 + 0.5797 * (dia ^ 2)
biomass
jpeg(paste(species.name, '.jpg', sep = '')
plot (biomass, main=species.name, xlab=dbh in cm, ylab=biomass in kg)
dev.off()

On Tue, Apr 12, 2011 at 9:54 PM, Benjamin Caldwell
btcaldw...@berkeley.eduwrote:

 Evening folks,

 I'm trying to print a series of graphs to .jpeg using a variable as the
 title, but run into the difficultly that I can't find a way to append the
 file extension to the .jpeg (in this case extensionless!) files.

 Example:
 
 species.name=CussoniaHolstii
 dia-10:100
 biomass = -21.4863 + 0.5797 * (dia ^ 2)
 biomass
 jpeg(species.name)
 plot (biomass, main=species.name, xlab=dbh in cm, ylab=biomass in kg)
 -
 The output is CussoniaHolstii, but I want CussoniaHolstii.jpg. The help
 file
 for jpeg() specifies that the name include the extension (e.g.
 jpeg(CussoniaHolstii.jpg) but then I'd have to input the file name each
 time.

 Any help or workaround much appreciated.
 *
 *
 *Ben Caldwell*

[[alternative HTML version deleted]]

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




-- 
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 to .jpeg

2011-04-12 Thread Luke Miller
And of course I need to close the parentheses completely on jpeg().
Apologies for the double post.

jpeg(paste(species.name, '.jpg', sep = ''))

On Tue, Apr 12, 2011 at 10:02 PM, Luke Miller mille...@gmail.com wrote:

 How about using paste() inside the jpeg() function to append a '.jpg' to
 the end of your species name?
 See the change below. I also added a dev.off() to close the newly created
 jpeg.


 species.name=CussoniaHolstii
 dia-10:100
 biomass = -21.4863 + 0.5797 * (dia ^ 2)
 biomass
 jpeg(paste(species.name, '.jpg', sep = ''))

 plot (biomass, main=species.name, xlab=dbh in cm, ylab=biomass in kg)
 dev.off()


 On Tue, Apr 12, 2011 at 9:54 PM, Benjamin Caldwell 
 btcaldw...@berkeley.edu wrote:

 Evening folks,

 I'm trying to print a series of graphs to .jpeg using a variable as the
 title, but run into the difficultly that I can't find a way to append the
 file extension to the .jpeg (in this case extensionless!) files.

 Example:
 
 species.name=CussoniaHolstii
 dia-10:100
 biomass = -21.4863 + 0.5797 * (dia ^ 2)
 biomass
 jpeg(species.name)
 plot (biomass, main=species.name, xlab=dbh in cm, ylab=biomass in kg)
 -
 The output is CussoniaHolstii, but I want CussoniaHolstii.jpg. The help
 file
 for jpeg() specifies that the name include the extension (e.g.
 jpeg(CussoniaHolstii.jpg) but then I'd have to input the file name each
 time.

 Any help or workaround much appreciated.
 *
 *
 *Ben Caldwell*

[[alternative HTML version deleted]]

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




 --
 ___
 Luke Miller
 Postdoctoral Researcher
 Marine Science Center
 Northeastern University
 Nahant, MA
 (781) 581-7370 x318





-- 
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?

2011-03-16 Thread luke-tierney

Just as a heads-up: it is likely that unlocking the bindings in base
for pi, T, F, probably all BULTIN and SPECIAL functions, and possibly
more, will start signaling warnings in the near future.  Doing this
may be useful at times for debugging but it can mess up assumptions
others make about how things in base work and so reduce code
reliability.

Best,

luke

On Wed, 16 Mar 2011, Allan Engelhardt wrote:




On 16/03/11 15:04, Gabor Grothendieck wrote:
On Wed, Mar 16, 2011 at 10:54 AM, Allan Engelhardtall...@cybaea.com 
wrote:

[...]
Yes, but you can still print(base::pi) and rm(pi) to get back to our flat
world, and you can't


assign(pi, 4, pos = package:base)

Error in assign(pi, 4, pos = package:base) :
  cannot change value of locked binding for 'pi'

Just a feature of the search path.  Morale: if you want base::pi, write
base::pi.


Try this:


old.pi- pi
assignInNamespace(pi, 2.3, ns = base)
pi

[1] 2.3

base::pi

[1] 2.3


Ah!  assignInNamespace does an unlockBinding under the covers which obviously 
is Evil(tm).  The answer clearly is to do


assignInNamespace(unlockBinding, function (...) {warning(be safe);}, 
ns=base)


in your .Rprofile!  Let's Keep R Safe, Folks!

Allan

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



--
Luke Tierney
Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:  l...@stat.uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?

2011-03-16 Thread luke-tierney

On Wed, 16 Mar 2011, Gabor Grothendieck wrote:


On Wed, Mar 16, 2011 at 11:49 AM,  luke-tier...@uiowa.edu wrote:

Just as a heads-up: it is likely that unlocking the bindings in base
for pi, T, F, probably all BULTIN and SPECIAL functions, and possibly
more, will start signaling warnings in the near future.  Doing this
may be useful at times for debugging but it can mess up assumptions
others make about how things in base work and so reduce code
reliability.


That seems ok for pi, T and F but if its extended to everything in
base then I would hope there is a nowarn= argument or other easy way
to avoid the warning message.



That would defeat the purpose.  Unlocking things in base may be useful
for experimenting or debugging but it is not a good idea otherwise.
[? assignInNamespace could be more explicit on htis and will be soon.]
There is a reason we lock bindings in the first place, and that is so
one can assume that these bindings have certain values and certain
properties and one can write reliable programs against these
assumptions.

Best,

luke

--
Luke Tierney
Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:  l...@stat.uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?

2011-03-16 Thread luke-tierney

On Wed, 16 Mar 2011, Barry Rowlingson wrote:


On Wed, Mar 16, 2011 at 4:16 PM,  luke-tier...@uiowa.edu wrote:


That would defeat the purpose.  Unlocking things in base may be useful
for experimenting or debugging but it is not a good idea otherwise.


You are making experimenting in R more awkward? Then I'm throwing
That would defeat the purpose straight back at you. I remember when
R was all about the experimenting. Of course it was called Splus back
then and was only available in grainy black-and-white...



And how does seeing a warning reminding you that you are dong
something experimental that might break things make experimenting more
awkward?  Since you wouldn't like to see such warnings in production
code this does make doing something in production code that can break
other people's code more awkward.  As I do actually care bout whether
my code works or not I'm fine with that.

luke


Oh well, I guess its one small step towards becoming a proper
grown-up language.

Barry



--
Luke Tierney
Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:  l...@stat.uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Does R have a const object?

2011-03-16 Thread luke-tierney

On Wed, 16 Mar 2011, Gabor Grothendieck wrote:


On Wed, Mar 16, 2011 at 12:16 PM,  luke-tier...@uiowa.edu wrote:

On Wed, 16 Mar 2011, Gabor Grothendieck wrote:


On Wed, Mar 16, 2011 at 11:49 AM,  luke-tier...@uiowa.edu wrote:


Just as a heads-up: it is likely that unlocking the bindings in base
for pi, T, F, probably all BULTIN and SPECIAL functions, and possibly
more, will start signaling warnings in the near future.  Doing this
may be useful at times for debugging but it can mess up assumptions
others make about how things in base work and so reduce code
reliability.


That seems ok for pi, T and F but if its extended to everything in
base then I would hope there is a nowarn= argument or other easy way
to avoid the warning message.



That would defeat the purpose.  Unlocking things in base may be useful
for experimenting or debugging but it is not a good idea otherwise.
[? assignInNamespace could be more explicit on htis and will be soon.]
There is a reason we lock bindings in the first place, and that is so
one can assume that these bindings have certain values and certain
properties and one can write reliable programs against these
assumptions.



Its useful for being able to set defaults for arguments that do not
have defaults.  That cannot break existing programs.


Until the next program decides do co change those defaults and either
can't or does and you end up with incompatible assumptions.  It also
make the code with the added defaults inconsistent with the
documentation though, which is not a good idea.  It may seem
convenient but it isn't a good idea in production code that is
intended to play well with other production code.


Note that if this feature is implemented in a heavy handed manner it
could cause havoc as at least one package that is depended upon by
literally dozens of other packages (and possibly hundreds if one takes
into account dependencies of dependencies) cannot function.


The reason I sent my initial message is so those who do this sort of
thing can start thinking about other approaches.  I do not expect to
need this change for closures any time soon, but will need it for
constants and primitives.  It may be useful for some closures as well,
so that change may come farther down the line.

luke

--
Luke Tierney
Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:  l...@stat.uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Make R 'Beep'

2011-03-08 Thread Luke Miller
Including the \a escape sequence inside a cat() call should make a simple
beep.

 cat(All done! \a \n)

On Tue, Mar 8, 2011 at 5:01 AM, Alaios ala...@yahoo.com wrote:

 Dear all,
 I would like to ask you if R can produce any kind of sound. It would be
 useful when code execution stops R to notify me by playing some sound.


 Is that possible in R?

 I would like to thank you in advance for your help

 Best Regards
 Alex

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




-- 
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA
(781) 581-7370 x318

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Does POSIXlt extract date components properly?

2011-03-01 Thread Luke Miller
Month counts from 0 in POSIXlt objects, so that April is month 3 in your
example, January being month 0.

Year counts from 1900 in POSIXlt objects, so that 2005 should return as 105
in your example.

All of the other fields in POSIXlt should return values that you might
expect them to a priori. Keep an eye on daylight savings time adjustments if
they apply in your time zone.

On Tue, Mar 1, 2011 at 12:01 PM, Seth W Bigelow sbige...@fs.fed.us wrote:

 I would like to use POSIX classes to store dates and extract components of
 dates. Following the example in Spector (Data Manipulation in R), I
 create a date

  mydate = as. POSIXlt('2005-4-19 7:01:00')

 I then successfully extract the day with the command

  mydate$day
 [1] 19

 But when I try to extract the month

   mydate$mon
 [1] 3

 it returns the wrong month. And mydate$year is off by about 2,000 years.
 Am I doing something wrong?

 Dr. Seth  W. Bigelow
 Biologist, USDA-FS Pacific Southwest Research Station
 1731 Research Park Drive, Davis California
 sbige...@fs.fed.us /  ph. 530 759 1718
[[alternative HTML version deleted]]

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




-- 
___
Luke Miller
Postdoctoral Researcher
Marine Science Center
Northeastern University
Nahant, MA

[[alternative HTML version deleted]]

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


  1   2   >