[Rd] R-ints Argument Evaluation has out of date examples

2016-12-23 Thread Richard Cotton
In R-ints section 1.5 https://cran.r-project.org/doc/manuals/r-devel/R-ints.html#Argument-evaluation it states > Note that being a special/builtin is separate from being primitive > or .Internal: quote is a special primitive, + is a builtin primitive, > cbind is a special .Internal and grep is a

[Rd] .S4methods inconsistent behavior with methods, .S3methods

2016-11-03 Thread Richard Cotton
If I call .S4methods(sd) I get the error ## Error in getGeneric(generic.function) : ## argument 'f' must be a string, generic function, or primitive: got an ordinary function By contrast, methods and .S3methods just state that no methods are found. methods(sd) ## no methods found S3methods(s

[Rd] S3 dispatch for primitive generics

2016-10-31 Thread Richard Cotton
I seem to recall reading that for primitive generics, S3 will dispatch on class first, then on mode. Unfortunately, I can't find the place that I read this, and I don't trust my memory. 1) Is this correct? Or is it dispatch on class, then on typeof? Or something else? 2) Where is this documente

Re: [Rd] improve 'package not installed' load errors?

2016-10-27 Thread Richard Cotton
> A side question, which I do not know the answer to, is how users get > themselves into this state. I've fallen over this a few times. It happens when you have multiple R sessions running, and R tries to update Rcpp while it is loaded in the other session. For example, I'm working on one proje

[Rd] using with inside loop breaks next

2016-10-27 Thread Richard Cotton
If I want to use with inside a loop, it seems that next gets confused. To reproduce: for(lst in list(list(a = 1), list(a = 2), list(a = 3))) { with(lst, if(a == 2) next else print(a)) } I expect 1 and 3 to be printed, but I see [1] 1 Error in eval(expr, envir, enclos) : no loop for break/ne

Re: [Rd] Is it possible to retrieve the last error? (not error *message*)

2016-05-05 Thread Richard Cotton
I wondered the same thing a few days ago. https://stackoverflow.com/questions/36966036/how-to-get-the-last-error The here's the solution from that discussion: get_last_error <- function() { tr <- .traceback() if(length(tr) == 0) { return(NULL) } tryCatch(eval(parse(text = tr[[1]]))

[Rd] Too many spaces in deparsed complex numbers with digits17 control option

2016-05-04 Thread Richard Cotton
If you set the "digits17" control option in deparse, you get a lot of unnecessary space in the representation of complex numbers. > deparse(0 + 0i) [1] "0+0i" > deparse(0 + 0i, control = "digits17") [1] "0 + 0i" As far as I can tell, the logic for this comes from this piece of /sr

[Rd] capturing warnings using capture.output

2015-11-23 Thread Richard Cotton
>From the Details section of ?capture.output: Messages sent to stderr() (including those from message, warning and stop) are captured by type = "message". Note that this can be "unsafe" and should only be used with care. Capturing messages works as expected: capture.output(message("!!!"), type =

Re: [Rd] Best way to implement optional functions?

2015-11-23 Thread Richard Cotton
See \code{\link[originating_pkg]{some_function}}. #' @name some_function #' @export NULL I borrowed this idea from dplyr's reexporting of magrittr's pipe. On 17 November 2015 at 00:02, Duncan Murdoch wrote: > On 16/11/2015 4:00 AM, Richard Cotton wrote: >> >> On

Re: [Rd] Best way to implement optional functions?

2015-11-16 Thread Richard Cotton
On 22 October 2015 at 22:55, Duncan Murdoch wrote: > I'm planning on adding some new WebGL functionality to the rgl package, but > it will pull in a very large number of dependencies. Since many people won't > need it, I'd like to make the new parts optional. > Can people suggest other packages t

[Rd] PDFs and SVGs containing rasterGrobs don't display correctly in some other software

2015-11-05 Thread Richard Cotton
I've just been trying to post-process some R-created heatmaps using Inkscape, but I can't get them to display correctly in that software. To reproduce: library(grid) r <- as.raster(matrix(runif(25), 5, 5)) pdf("test.pdf") grid.newpage() grid.raster(r, interpolate = FALSE) dev.off() This figure s

[Rd] Differences in printing UTF-8 strings to stdout vs. stderr under Windows

2015-09-22 Thread Richard Cotton
It seems that under Windows, some UTF-8 strings that print OK to stdout do not print correctly to stderr. To reproduce: x <- "\ub124" cat(x, file = stdout()) ## 네 cat(x, file = stderr()) ## Original motivating problem here: https://stackoverflow.com/questions/32696241/how-to-display-a-message-w

Re: [Rd] Using IDs to suppress specific messages and warnings

2015-09-10 Thread Richard Cotton
Thanks Luke, On 10 September 2015 at 14:47, wrote: > Conditions have classes and the condition system is designed around > the idea that classes would be used for this sort of thing. That is > already how tryCatch and withCallingHandlers discriminate the > conditions to handle. That makes sense

Re: [Rd] Proposed change in file.exists() to tolerate Windows

2015-09-10 Thread Richard Cotton
Two solutions: 1. Use the wrapper function is_existing_file in assertive. 2. Use standardize_path in pathological before you call file.exists. On 27 August 2015 at 17:02, Paul Johnson wrote: > I'm writing to ask if R Core would make file.exists more Windows > tolerant when the argument has a

[Rd] Using IDs to suppress specific messages and warnings

2015-09-10 Thread Richard Cotton
The suppressMessages and suppressWarnings functions currently suppress all the message or warnings that are generated by the input expression. The ability to suppress only specific messages or warnings is sometimes useful, particularly for cases like file import where there are lots of things that

[Rd] Are import-reexport-only packages allowed on CRAN?

2015-07-05 Thread Richard Cotton
One piece of feedback that I received at useR was that the assertive package is getting too big, and should be broken down into smaller pieces. I want to split the functionality into assertive.base, assertive.types, and a few others, then have the assertive package as a virtual package (suggestion

Re: [Rd] Unicode display problem with data frames under Windows

2015-05-26 Thread Richard Cotton
deal with it. > > Since most of the people who tend to do that generally use systems in UTF-8 > locales where this isn't a problem, or don't use Windows, it is languishing. Thanks for the link and the explanation of why the bug exists. >> On May 25, 2015 9:39 AM, "Richard C

[Rd] Unicode display problem with data frames under Windows

2015-05-25 Thread Richard Cotton
Here's a data frame with some Unicode symbols (set intersection and union). d <- data.frame(x = "A \u222a B \u2229 C") Printing this data frame under R 3.2.0 patched (r68378) and Windows 7, I see d ## x ## 1 A B n C Printing the column itself works fine. d$x ## [1] A ∪ B ∩ C

Re: [Rd] Possible values for R version status

2015-03-23 Thread Richard Cotton
Thanks for this. You are right that it's a lowercase "a"; the documentation on the R.Version help page is incorrect. That describes status as 'the status of the version (e.g., "Alpha")'. On 23 March 2015 at 16:36, Duncan Murdoch wrote: > On 23/03/2015 9

[Rd] Possible values for R version status

2015-03-23 Thread Richard Cotton
Is there a complete list somewhere of the possible values for R's status, as returned by version$status? I know about these values: Stable: "" Devel: "Under development (unstable)" Patched: "Patched" Release candidate: "RC" Alpha: "Alpha" Are there any others that I've missed? __

Re: [Rd] update.packages with ask = FALSE will sometimes ask about updates

2015-02-13 Thread Richard Cotton
On 13 February 2015 at 10:11, Prof Brian Ripley wrote: > On 11/02/2015 10:46, Richard Cotton wrote: > > The 'at a minimum' information required by the posting guide is conspicuous > by its absence. > > At a guess, this is R-devel and Windows. What I'm running

[Rd] update.packages with ask = FALSE will sometimes ask about updates

2015-02-11 Thread Richard Cotton
Today while running update.packages(ask = FALSE), R stopped to ask me a question: There are binary versions available but the source versions are later: binary source needs_compilation KernSmooth 2.23-13 2.23-14 TRUE mixture1.2 1.3 TRUE Do you

Re: [Rd] \U with more than 4 digits returns the wrong character

2014-12-04 Thread Richard Cotton
g/doc/manuals/r-release/R-lang.html > http://www.markvanderloo.eu > --- > If you cannot quantify it, > you don't know what you're talking about > > > On Thu, Dec 4, 2014 at 8:00 PM, Richard Cotton wrote: >&

[Rd] \U with more than 4 digits returns the wrong character

2014-12-04 Thread Richard Cotton
If I type a character using \U syntax that has more than 4 digits, I get the wrong character. For example, "\U1d4d0" should print a mathematical bold script capital A. See http://www.fileformat.info/info/unicode/char/1d4d0/index.htm On my machine, it prints the Hangul character corresponding t

[Rd] normalizePath is sometimes very slow for nonexistent UNC paths

2014-09-07 Thread Richard Cotton
I'm having an issue with occasionally slow-running calls to normalizePath. If the path is a non-existent UNC path, then normalizePath sometimes takes 6 or 7 seconds to run, rather than its usual few microseconds. My big problem is that I can't reliably reproduce this across machines. The example

[Rd] The behaviour of setting names differs between lists and atomic vectors

2014-08-21 Thread Richard Cotton
If you set the names in a list, some cat-style processing seems to happen. For example, backslashes are modified. This behaviour doesn't happen with atomic vectors. Compare, for example: setNames(1, "a\\b") ## a\\b ## 1 setNames(list(1), "a\\b") ## $`a\b` ## [1] 1 Notice that the name of the

[Rd] Is using devtools::release no longer allowed?

2014-08-19 Thread Richard Cotton
I recently tried to submit a package to CRAN using the release function in the devtools package and got the response: > The policies asked you to use the webform: do so in future. I think that the relevant line in the policies are: > When submitting a package to CRAN you should use the submissio

[Rd] --vanilla option for creating cluster nodes

2014-05-13 Thread Richard Cotton
When a PSOCK cluster (maybe other cluster types too) is created by the parallel package, an Rscript process is spawned for each node. At least by default, the Rprofile.site file is read for each node that is created, which can constitute the majority of the time to create a cluster. See: http://

[Rd] A rep_each function

2014-03-23 Thread Richard Cotton
The rep function is very versatile, but that versatility comes at a cost: it takes a bit of effort to learn (and remember) its syntax. This is a problem, since rep is one of the first functions many beginners will come across. Of the three main uses of rep, two have simpler alternatives. rep(x, t

Re: [Rd] How deep can/should lists be nested?

2012-10-14 Thread Richard Cotton
rian Ripley wrote: > On 14/10/2012 12:53, Duncan Murdoch wrote: >> >> On 12-10-14 7:06 AM, Richard Cotton wrote: >>> >>> I started idly wondering how deeply lists could be nested, and >>> couldn't find an explicit limit in the documentation.

[Rd] How deep can/should lists be nested?

2012-10-14 Thread Richard Cotton
I started idly wondering how deeply lists could be nested, and couldn't find an explicit limit in the documentation. With this simple test a_list <- list() count <- 0 repeat { a_list[[1]] <- a_list count <- count + 1 } my (Win7, R-2.16.0 devel) machine threw an error when count got close to

Re: [Rd] Expected behaviour of is.unsorted?

2012-05-23 Thread Richard Cotton
>> is.unsorted(data.frame(1:2)) > [1] FALSE >> is.unsorted(data.frame(2:1)) > [1] FALSE >> is.unsorted(data.frame(1:2,3:4)) > [1] TRUE >> is.unsorted(data.frame(2:1,4:3)) > [1] TRUE > > IIUC, is.unsorted is intended for atomic vectors only (description of x in > ?is.unsorted). Indeed the C source (

[Rd] Codoc mismatch for roxygen-documented foo<- functions

2012-05-22 Thread Richard Cotton
I have a roxygen2 documented package with functions for getting and setting an attribute. #' Get or set the foo attribute. #' #' Dummy function! #' #' @param x Object to hold the attribute. #' @param value Value to set the attribute to. #' @return The get function returns the "foo" attribute of \c

[Rd] Why is there no within.environment function?

2012-03-21 Thread Richard Cotton
If I want to assign some variables into an environment, it seems natural to do something like e <- new.env() within(e, { x <- 1:5 y <- runif(5) } ) This throws an error, since within.environment doesn't exist.  I realise I can work around it using as.environment(within(as.lis

[Rd] .Internal(inspect(x)) gives overly verbose output for reference classes

2012-03-07 Thread Richard Cotton
Even for an extremely simple instance of a reference class x <- setRefClass("x") y <- x$new() calling the internal inspect function .Internal(inspect(y)) produces enough output that it takes several minutes to print to the console.  (Actually I gave up and terminated the command after ~10 mins.

[Rd] Speed issue when writing to RGui console from tcl/tk GUI

2011-12-19 Thread Richard Cotton
It seems that there are speed issues when printing to the R console from a tcl/tk GUI. Here are functions to write a lot of output, and to display how long it takes. printsalot <- function(n) { for(i in 1:n) cat(i, fill = TRUE) } timings <- function(n = 1e3) { print(system.time(printsalot(n)

[Rd] possible bug with log of complex zero

2011-01-10 Thread Richard . Cotton
Notice that > log(0i) [1] -Inf+0i but > log(0i, ) [1] -Inf+NaNi To me, it seems that these should be the same value. I'll record this on the bug tracker if you agree; otherwise please can someone explain why this is the case. Regards, Richie. Mathematical Sciences Unit HSL 4D Pie Charts

[Rd] n=1 default for random number generators

2009-11-16 Thread Richard Cotton
One tiny thing that would be very nice to have is a default value of n=1 in the random number generator functions, enabling, e.g., runif() instead of runif(1). This won't break anyone's existing code and ought to be relatively straightforward to do. Is there anyone in the core team who would b

[Rd] RGui Configuration editor crashes when using an unlisted font (PR#13780)

2009-06-24 Thread richard . cotton
Full_Name: Richard Cotton Version: 2.9.0 OS: Windows XP, SP2, 32 bit Submission from: (NULL) (87.102.99.18) To reproduce the crash: 1. Create an RConsole file for your user account. 2. Close R. 3. Manually edit the font line to include a font that is not on the standard list of available

[Rd] RGui Configuration Editor crashes when using an unlisted font

2009-06-19 Thread Richard . Cotton
I am using R2.9.0 under Windows XP SP 2 (32-bit). I just discovered a rather excellent programming font (http://www.dafont.com/bitstream-vera-mono.font). Since it isn't one of the fonts listed as an option in the RGui Configuration Editor, I manually editted my RConsole file font line to font

Re: [Rd] Colour Schemes

2009-05-21 Thread Richard . Cotton
I'm going to take your second example first. > The base graphics "image" function has zlim arguments which let you do: > > z=outer(1:10,1:10,"*") > image(z) > image(z/2, zlim=range(z)) > > but again, not obvious, and complex/impossible when using more > sophisticated colour mappings. The w

Re: [Rd] Colour Schemes

2009-05-21 Thread Richard . Cotton
> I've been thinking hard about generating colour schemes for data. > There's quite a bit of existing code scattered in various packages for > playing with colours and colour palettes, but I can't find the sort of > thing I'm after for applying colours to data... > > To my mind a colour scheme is

Re: [Rd] A strange behaviour of file.path in Windows? (PR#13119)

2008-10-03 Thread Richard . Cotton
> If you send these lines of code: > > outdir="c:/pippo" > file.path(outdir,"pluto.html") > > R replies correctly: > > [1] "c:/pippo/pluto.html" > > But if you change the first steps to: > > outdir="" > file.path(outdir,"pluto.html") > > R replies (uncorrectly, I think) > > [1] "/c:/pippo/pl

[Rd] Filename bug in png

2008-07-03 Thread Richard Cotton
In R2.7.1, the first line of the body of png() reads: checkIntFormat(filename) This should really be: if (!checkIntFormat(file)) stop("invalid 'file'") Otherwise a command such as png("foo%s.png") causes R to crash (see bug #10571). - Regards, Richie. Mathematical Sciences Unit H

Re: [Rd] Call R from C#

2008-04-08 Thread Richard Cotton
guox wrote: > > I would like to call functions/objects of R from > C#.NET environment. I was wondering whether or not > it is possible. If yes, could you please give me some suggestions > on how to approach it (any examples/documentation on this)? Thanks! > Here are some instructions on callin

Re: [Rd] %s in filename when opening device causes crash (PR#10571)

2008-01-16 Thread Richard Cotton
Prof Brian Ripley wrote: > >> Yes. The problem is of course that we do want a sprintf() format there >> for "Rplot%03d.pdf" et al. One option would be to escape "%" except >> when in (regexp) "%[0-9]*d", which seems nontrivial, but not impossible. > > But there are other integer formats (%i,

Re: [Rd] %s in filename when opening device causes crash (PR#10571)

2008-01-15 Thread Richard . Cotton
> > Using %s in a filename when opening a device causes R to crash, e.g., > > > > pdf("foo%s.pdf") > > win.metafile("foo%s.wmf") > > postscript("foo%s.ps") > > Do you have a workaround for this? Since that is done at C level, we > can't easily trap this (especially on Windows), and the list of p

[Rd] %s in filename when opening device causes crash (PR#10571)

2008-01-14 Thread richard . cotton
Full_Name: Richard Cotton Version: 2.6.1 OS: Windows XP (32bit) Submission from: (NULL) (193.119.236.82) Using %s in a filename when opening a device causes R to crash, e.g., pdf("foo%s.pdf") win.metafile("foo%s.wmf") postscript("foo%s.ps") __