[Rd] cannot destroy connection (?) created by readLines in a tryCatch

2017-12-14 Thread Gábor Csárdi
Consider this code. This is R 3.4.2, but based on a quick look at the NEWS, this has not been fixed. tryCatch( readLines(tempfile(), warn = FALSE)[1], error = function(e) NA, warning = function(w) NA ) rm(list=ls(all.names = TRUE)) gc() showConnections(all = TRUE) If you run it, you'll ge

Re: [Rd] cannot destroy connection (?) created by readLines in a tryCatch

2017-12-14 Thread Gabriel Becker
Gabor, You can grab the connection and destroy it via getConnection and then a standard close call. (it actually lists that it is "closed" already, but still in the set of existing connections. I can't speak to that difference). > tryCatch( + readLines(tempfile(), warn = FALSE)[1], + error

[Rd] xyTable(x,y) versus table(x,y) with NAs

2017-12-14 Thread Viechtbauer Wolfgang (SP)
Hi All, I asked this over at r-help, but didn't get any responses. As this seems like a bug (or at least undocumented behavior) to me, I'll try again here. It seems to me that xyTable() gets thrown off by NAs: x <- c(1, 1, 2, 2, 2, 3) y <- c(1, 2, 1, 3, NA, 3) table(x, y, useNA="always") xyTab

Re: [Rd] cannot destroy connection (?) created by readLines in a tryCatch

2017-12-14 Thread Gábor Csárdi
On Thu, Dec 14, 2017 at 7:56 PM, Gabriel Becker wrote: > Gabor, > > You can grab the connection and destroy it via getConnection and then a > standard close call. Yeah, that's often a possible workaround, but since this connection was opened by readLines() internally, I don't necessarily know whi

Re: [Rd] cannot destroy connection (?) created by readLines in a tryCatch

2017-12-14 Thread Gabriel Becker
On Thu, Dec 14, 2017 at 12:17 PM, Gábor Csárdi wrote: > On Thu, Dec 14, 2017 at 7:56 PM, Gabriel Becker > wrote: > > Gabor, > > > > You can grab the connection and destroy it via getConnection and then a > > standard close call. > > Yeah, that's often a possible workaround, but since this connec

Re: [Rd] cannot destroy connection (?) created by readLines in a tryCatch

2017-12-14 Thread Tierney, Luke
Your guess is wrong. More when I have a sensible keyboard Sent from my iPhone On Dec 15, 2017, at 10:21 AM, Gabriel Becker mailto:gmbec...@ucdavis.edu>> wrote: On Thu, Dec 14, 2017 at 12:17 PM, Gábor Csárdi mailto:csardi.ga...@gmail.com>> wrote: On Thu, Dec 14, 2017 at 7:56 PM, Gabriel Becker

[Rd] format() doesn't propagate the dim and dimnames when underlying type of array is "list"

2017-12-14 Thread Hervé Pagès
Hi, Here is how to reproduce: With a matrix of atomic type m1 <- matrix(1:12, ncol=3, dimnames=list(letters[1:4], LETTERS[1:3])) typeof(m1) # [1] "integer" m1 # A B C # a 1 5 9 # b 2 6 10 # c 3 7 11 # d 4 8 12 format(m1) #

Re: [Rd] cannot destroy connection (?) created by readLines in a tryCatch

2017-12-14 Thread luke-tierney
This has nothing to do with on.exit. It is an iteraction between where the warning is signaled in 'file' and your _exiting_ warning handler. This combination has the same issue, tryCatch(file(tempfile(), "r"), warning = identity) showConnections(all = TRUE) as does options(warn=2) file(tempfile

Re: [Rd] cannot destroy connection (?) created by readLines in a tryCatch

2017-12-14 Thread Gábor Csárdi
Thanks for tracking this down. Yeah, I should use suppressWarnings(), you are right. Although, readLines() might throw another warning, e.g. for incomplete last lines, and you don't necessarily want to suppress that. TBH I am not sure why that warning is given: ❯ con <- file(tempfile()) ❯ open(co