Re: [Rd] Unicode whitespace
I presume you want this only in a UTF-8 locale? Currently this is done by static int SkipSpace(void) { int c; while ((c = xxgetc()) == ' ' || c == '\t' || c == '\f') /* nothing */; return c; } in gram.c. We could make use of isspace and its wide-char equivalent iswspace. However: - there is the perennial debate over whether \v is whitespace. R-lang says Although not strictly tokens, stretches of whitespace characters (spaces and tabs) serve to delimit tokens in case of ambiguity, which suggests it has a minimal view of whitespace. - iswspace is often rather unreliable. E.g. glibc says The wide character class "space" always contains at least the space character and the control characters '\f', '\n', '\r', '\t', '\v'. and I think it usually does not contain other forms of spaces. More seriously The behaviour of iswspace() depends on the LC_CTYPE category of the current locale. so what is a space will depend on the encoding (hence my question about UTF-8). And Ei-ji Makama was replaced iswspace on MacOS X, because apparently it is wrongly implemented. - it would complicate the parser as look-ahead would be needed (you would need to read the next mbcs, check it it were whitespace and pushback if needed). We do that elsewhere, though. The only one of these 'spaces' I have much sympathy for is NBSP (which is also fairly easy to generate in CP1252). It would be easy to add that. Otherwise I am not convinced it is worth the work (and added uncertainty). On Fri, 4 Jan 2008, hadley wickham wrote: It would be nice if R ignored more unicode white space characters. For example, if I have "\u2028" in a command (which I get from a line-break in keynote) I get the following error: qplot(carat, price, data = diamonds, ÿÿ colour=clarity) Error: unexpected input in "qplot(carat, price, data = diamonds, ?" And occasionally have such problems when copying and pasting from emails as well. Wikipedia lists the following codepoints as whitespace (I'm sure there is a more definitive reference but I could not find one with some quick googling): U0009-U000D (Control characters, containing TAB, CR and LF) Most of those are not normally considered whitespace. U0020 SPACE U0085 NEL U00A0 NBSP U1680 OGHAM SPACE MARK U180E MONGOLIAN VOWEL SEPARATOR U2000-U200A (different sorts of spaces) U2028 LSP U2029 PSP U202F NARROW NBSP U205F MEDIUM MATHEMATICAL SPACE U3000 IDEOGRAPHIC SPACE would it be possible for R to treat these all in the same way? (Or does it already but my R is misconfigured?) Hadley -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] is(x, "parent") returns FALSE when class(x) is c("child", "parent") (PR#10549)
is() does not catch parent S3 classes: > library(splines) > temp <- bs(1:99, df=5) > class(temp) [1] "bs""basis" > is(temp, "basis") [1] FALSE In contrast, is() does catch parent S4 classes: > library(copula) > norm.cop <- ellipCopula("normal", param = c(0.5, 0.6, 0.7), + dim = 3, dispstr = "un") > is(norm.cop, "copula") [1] TRUE > class(norm.cop) [1] "normalCopula" --please do not edit the information below-- Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = major = 2 minor = 6.1 year = 2007 month = 11 day = 26 svn rev = 43537 language = R version.string = R version 2.6.1 (2007-11-26) Windows XP (build 2600) Service Pack 2.0 Locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 Search Path: .GlobalEnv, package:splines, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] checking whether the name space can be loaded with stated dependencies
On 1/4/08, Henrik Bengtsson <[EMAIL PROTECTED]> wrote: > On 04/01/2008, hadley wickham <[EMAIL PROTECTED]> wrote: > > On 1/4/08, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > > > What it is trying is > > > > > > % env R_DEFAULT_PACKAGES=NULL R > > > > > > > loadNamespace("ggplot2") > > > > > > The test is not new, so it would seem to be a change in ggplot2 since the > > > version on CRAN. My guess is the your package is doing top-level > > > computations, which `Writing R Extensions' warns against: > > > > > >The R code files should only create R objects and not call functions > > >with side effects such as require and options. > > > > Thanks for the additional info. I've grepped for ^[^#\n ]+\( (which I > > think should find any top-level function call) and didn't find > > Not the correct pattern; there can be spaces after the function name > the first parentesis, e.g. > > > rnorm (3) > [1] 0.6127487 0.8150284 -0.7170449 Well, yes, but I never write functions like that, and I hardly need to search my own code for idioms that I never use. > More, the above regular expression will not detect function calls > starting with a space, neither expressions such as "3+3" although I > don't think they would generate the above NOTE/error. > > > pattern <- "^[^#\n ]+\\(" > > regexpr(pattern, "rnorm(3)") > [1] 1 > > regexpr(pattern, "rnorm (3)") > [1] -1 > > regexpr(pattern, " rnorm(3)") > [1] -1 > > regexpr(pattern, "3+3") > [1] -1 > > Also, what is the newline ('\n') doing in the negated set - isn't grep > done line by line? I wasn't actually using grep. > > anything. I certainly can't think of any top level computations that > > I'm doing apart from creating R functions and objects. Is there > > anyway to get more details about what exactly I've done wrong? > > Calling traceback after loadNamespace isn't helpful. > > Start commenting out/exclude part of your source code and recheck for > the same error should do. Start from scratch by adding a > > foo <- function() { NA } > > and exclude everything else. If that works, leave 1st half out, then > 2nd and continue with "divide and conquer" until you narrow down the > problem. Sometimes it comes down to a single right bracket missed > out. Unfortunately a binary search isn't so easy when you have fairly complex dependencies between files. Hadley -- http://had.co.nz/ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Addendum: nls (with SSlogis model and upper limit) never returns (PR#10548)
Peter Dalgaard reminded me to be more specific about my computing platform; it's Debian 4.1.1-19 on a 32-bit Pentium 4 machine (Dell Optiplex GX620). The problem I described (nls not returning) also occurs with different data at other values of the scal parameter. Regards Hendrik Weisser -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] checking whether the name space can be loaded with stated dependencies
On 04/01/2008, hadley wickham <[EMAIL PROTECTED]> wrote: > On 1/4/08, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > > What it is trying is > > > > % env R_DEFAULT_PACKAGES=NULL R > > > > > loadNamespace("ggplot2") > > > > The test is not new, so it would seem to be a change in ggplot2 since the > > version on CRAN. My guess is the your package is doing top-level > > computations, which `Writing R Extensions' warns against: > > > >The R code files should only create R objects and not call functions > >with side effects such as require and options. > > Thanks for the additional info. I've grepped for ^[^#\n ]+\( (which I > think should find any top-level function call) and didn't find Not the correct pattern; there can be spaces after the function name the first parentesis, e.g. > rnorm (3) [1] 0.6127487 0.8150284 -0.7170449 More, the above regular expression will not detect function calls starting with a space, neither expressions such as "3+3" although I don't think they would generate the above NOTE/error. > pattern <- "^[^#\n ]+\\(" > regexpr(pattern, "rnorm(3)") [1] 1 > regexpr(pattern, "rnorm (3)") [1] -1 > regexpr(pattern, " rnorm(3)") [1] -1 > regexpr(pattern, "3+3") [1] -1 Also, what is the newline ('\n') doing in the negated set - isn't grep done line by line? > anything. I certainly can't think of any top level computations that > I'm doing apart from creating R functions and objects. Is there > anyway to get more details about what exactly I've done wrong? > Calling traceback after loadNamespace isn't helpful. Start commenting out/exclude part of your source code and recheck for the same error should do. Start from scratch by adding a foo <- function() { NA } and exclude everything else. If that works, leave 1st half out, then 2nd and continue with "divide and conquer" until you narrow down the problem. Sometimes it comes down to a single right bracket missed out. /Henrik > > > If you must deviate from that, you need to arrange for the environment you > > need: when loading a name space the Depends: packages are not loaded. > > Is this a recent change to R? The package appears to work fine after > installation so I presume this check is protecting me from some more > subtle danger. > > If it's helpful, my depends line is: > Depends: R (>= 2.6), grid, reshape (>= 0.8.0), proto, splines, MASS, > RColorBrewer, colorspace > > so only proto or RColorBrewer should be a problem. > > Hadley > > -- > http://had.co.nz/ > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] checking whether the name space can be loaded with stated dependencies
On Fri, 4 Jan 2008, hadley wickham wrote: > On 1/4/08, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: >> What it is trying is >> >> % env R_DEFAULT_PACKAGES=NULL R >> >>> loadNamespace("ggplot2") >> >> The test is not new, so it would seem to be a change in ggplot2 since the >> version on CRAN. My guess is the your package is doing top-level >> computations, which `Writing R Extensions' warns against: >> >>The R code files should only create R objects and not call functions >>with side effects such as require and options. > > Thanks for the additional info. I've grepped for ^[^#\n ]+\( (which I > think should find any top-level function call) and didn't find > anything. I certainly can't think of any top level computations that > I'm doing apart from creating R functions and objects. Is there > anyway to get more details about what exactly I've done wrong? As I said, that was a guess: if it is not the cause then I am in the dark. If you can send me the version doing this I can try to dig further. > Calling traceback after loadNamespace isn't helpful. > >> If you must deviate from that, you need to arrange for the environment you >> need: when loading a name space the Depends: packages are not loaded. > > Is this a recent change to R? No: that wording is ancient, and the test is not recent. > The package appears to work fine after > installation so I presume this check is protecting me from some more > subtle danger. The danger is that if some other package (or a user) does ggplot2::some_function_in_ggplot2 that this will fail if the package is not attached, similarly if a package name space imports from ggplot2. > If it's helpful, my depends line is: > Depends: R (>= 2.6), grid, reshape (>= 0.8.0), proto, splines, MASS, > RColorBrewer, colorspace > > so only proto or RColorBrewer should be a problem. > > Hadley > > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Evaluating R expressions
All, Thank you for the prompt and useful answers to my questions. I had missed references in 5.7.6 which would have answered some of the points. As Bill pointed out a newer version of acrobat would help, but the Sun system here is still running 5.0. (An oversubscribed sysadmin). Then I could have searched and at at least avoided the most trivial. All three comments were different, and all three helped. Terry T. "I see" said the blind carpenter, as he picked up his hammer and saw. (A favorite phrase of my mother's when something became clear). __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Evaluating R expressions from C
Hi Terry, Terry Therneau wrote: > I am currently puzzled by a passage in the R Extensions manual, section 5.10: > > SEXP lapply(SEXP list, SEXP expr, SEXP rho) > { >R_len_t i, n = length(list); >SEXP ans; > >if(!isNewList(list)) error("`list' must be a list"); >if(!isEnvironment(rho)) error("`rho' should be an environment"); >PROTECT(ans = allocVector(VECSXP, n)); >for(i = 0; i < n; i++) { > defineVar(install("x"), VECTOR_ELT(list, i), rho); > SET_VECTOR_ELT(ans, i, eval(expr, rho)); >} > > I'm trying to understand this code beyond just copying it, and don't find > definitions for many of the calls. PROTECT and SEXP have been well discussed > previously in the document, but what exactly are > R_len_t > defineVar this function defines the variable (SYMSXP; one type of SEXP) of its first argument, to have the value given by its second argument, in the environment defined by its third argument. There are lots of variants, these are largely in envir.c > install all symbols in R are unique (there is only one symbol named x, even though it might have bindings in many different environments). So to get the unique "thing" (a SYMSXP) you call install (line 1067 in names.c has a pretty brief comment to this effect). This makes it efficient to do variable look up, as we only need to compare pointers (within an environment), not compare names. > VECTOR_ELT access the indicated element (2nd arg) of the vector (first arg) > SET_VECTOR_ELT set the indicated element (2nd arg), of the vector (1st arg) to the value (3rd arg) > > The last I also found in 5.7.4, but it's not defined there either. > > So: >What do these macros do? Some I could guess, like is.Environment; and I'm > fairly confident of R_len_t. Others I need some help. >Perhaps they are elswhere in the document? (My version of acrobat can't > do > searches.) Is there another document that I should look at first? >Why "isNewList"? I would have guessed "isList". What's the difference? "old lists" are of the CAR-CDR variant, and largely only used internally these days. "new lists", are generic vectors, and are what users will almost always encounter (even users that program internals, you pretty much need to be messing with the language itself to run into the CAR-CDR variety). best wishes Robert > > Thanks for any help, > Terry Therneau > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > -- Robert Gentleman, PhD Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M2-B876 PO Box 19024 Seattle, Washington 98109-1024 206-667-7700 [EMAIL PROTECTED] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Evaluating R expressions from C
I am currently puzzled by a passage in the R Extensions manual, section 5.10: SEXP lapply(SEXP list, SEXP expr, SEXP rho) { R_len_t i, n = length(list); SEXP ans; if(!isNewList(list)) error("`list' must be a list"); if(!isEnvironment(rho)) error("`rho' should be an environment"); PROTECT(ans = allocVector(VECSXP, n)); for(i = 0; i < n; i++) { defineVar(install("x"), VECTOR_ELT(list, i), rho); SET_VECTOR_ELT(ans, i, eval(expr, rho)); } I'm trying to understand this code beyond just copying it, and don't find definitions for many of the calls. PROTECT and SEXP have been well discussed previously in the document, but what exactly are R_len_t defineVar install VECTOR_ELT SET_VECTOR_ELT The last I also found in 5.7.4, but it's not defined there either. So: What do these macros do? Some I could guess, like is.Environment; and I'm fairly confident of R_len_t. Others I need some help. Perhaps they are elswhere in the document? (My version of acrobat can't do searches.) Is there another document that I should look at first? Why "isNewList"? I would have guessed "isList". What's the difference? Thanks for any help, Terry Therneau __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Unicode whitespace
It would be nice if R ignored more unicode white space characters. For example, if I have "\u2028" in a command (which I get from a line-break in keynote) I get the following error: > qplot(carat, price, data = diamonds, colour=clarity) Error: unexpected input in "qplot(carat, price, data = diamonds, ?" And occasionally have such problems when copying and pasting from emails as well. Wikipedia lists the following codepoints as whitespace (I'm sure there is a more definitive reference but I could not find one with some quick googling): U0009-U000D (Control characters, containing TAB, CR and LF) U0020 SPACE U0085 NEL U00A0 NBSP U1680 OGHAM SPACE MARK U180E MONGOLIAN VOWEL SEPARATOR U2000-U200A (different sorts of spaces) U2028 LSP U2029 PSP U202F NARROW NBSP U205F MEDIUM MATHEMATICAL SPACE U3000 IDEOGRAPHIC SPACE would it be possible for R to treat these all in the same way? (Or does it already but my R is misconfigured?) Hadley -- http://had.co.nz/ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] nls (with SSlogis model and upper limit) never returns (PR#10544)
[EMAIL PROTECTED] wrote: > Full_Name: Hendrik Weisser > Version: 2.6.1 > OS: Linux > Submission from: (NULL) (139.19.102.218) > > > The following computation never finishes and locks R up: > > >> values <- list(x=10:30, y=c(23.85, 28.805, 28.195, 26.23, 25.005, 20.475, >> > 17.33, 14.97, 11.765, 8.857, 5.3725, 5.16, 4.2105, 2.929, 2.174, 1.25, 1.0255, > 0.612, 0.556, 0.4025, 0.173)) > >> y.max <- max(values$y) >> model <- nls(y ~ SSlogis(x, asym, xmid, scal), data=values, algorithm="port", >> > start=c(asym=y.max, xmid=15, scal=-0.5), upper=c(y.max, Inf, Inf)) > > This used to work with R version 2.5.1 patched. > The problem does _not_ occur if the parameter "scal=-0.5" in the nls call is > changed, e. g. to "scal=-0.6" or "scal=-0.4". > Simply calling "model <- nls(y ~ SSlogis(x, asym, xmid, scal), data=values)" > also works, but this does not use the upper bound for the asym parameter, > which > was the point. > > "Linux" is not a good enough description of your platform. This works fine on SUSE 10.2/x86_64. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] nls (with SSlogis model and upper limit) never returns (PR#10544)
Full_Name: Hendrik Weisser Version: 2.6.1 OS: Linux Submission from: (NULL) (139.19.102.218) The following computation never finishes and locks R up: > values <- list(x=10:30, y=c(23.85, 28.805, 28.195, 26.23, 25.005, 20.475, 17.33, 14.97, 11.765, 8.857, 5.3725, 5.16, 4.2105, 2.929, 2.174, 1.25, 1.0255, 0.612, 0.556, 0.4025, 0.173)) > y.max <- max(values$y) > model <- nls(y ~ SSlogis(x, asym, xmid, scal), data=values, algorithm="port", start=c(asym=y.max, xmid=15, scal=-0.5), upper=c(y.max, Inf, Inf)) This used to work with R version 2.5.1 patched. The problem does _not_ occur if the parameter "scal=-0.5" in the nls call is changed, e. g. to "scal=-0.6" or "scal=-0.4". Simply calling "model <- nls(y ~ SSlogis(x, asym, xmid, scal), data=values)" also works, but this does not use the upper bound for the asym parameter, which was the point. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] checking whether the name space can be loaded with stated dependencies
On 1/4/08, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > What it is trying is > > % env R_DEFAULT_PACKAGES=NULL R > > > loadNamespace("ggplot2") > > The test is not new, so it would seem to be a change in ggplot2 since the > version on CRAN. My guess is the your package is doing top-level > computations, which `Writing R Extensions' warns against: > >The R code files should only create R objects and not call functions >with side effects such as require and options. Thanks for the additional info. I've grepped for ^[^#\n ]+\( (which I think should find any top-level function call) and didn't find anything. I certainly can't think of any top level computations that I'm doing apart from creating R functions and objects. Is there anyway to get more details about what exactly I've done wrong? Calling traceback after loadNamespace isn't helpful. > If you must deviate from that, you need to arrange for the environment you > need: when loading a name space the Depends: packages are not loaded. Is this a recent change to R? The package appears to work fine after installation so I presume this check is protecting me from some more subtle danger. If it's helpful, my depends line is: Depends: R (>= 2.6), grid, reshape (>= 0.8.0), proto, splines, MASS, RColorBrewer, colorspace so only proto or RColorBrewer should be a problem. Hadley -- http://had.co.nz/ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] checking whether the name space can be loaded with stated dependencies
What it is trying is % env R_DEFAULT_PACKAGES=NULL R > loadNamespace("ggplot2") The test is not new, so it would seem to be a change in ggplot2 since the version on CRAN. My guess is the your package is doing top-level computations, which `Writing R Extensions' warns against: The R code files should only create R objects and not call functions with side effects such as require and options. If you must deviate from that, you need to arrange for the environment you need: when loading a name space the Depends: packages are not loaded. On Thu, 3 Jan 2008, hadley wickham wrote: > Can any one provide more details on this error that I'm getting from R > CMD check: > > * checking whether the name space can be loaded with stated > dependencies ... WARNING > Error in eval(expr, envir, enclos) : could not find function "proto" > Error: unable to load R code in package 'ggplot2' > Execution halted > > A namespace must be able to be loaded with just the base namespace loaded: > otherwise if the namespace gets loaded by a saved object, the session will > be unable to start. > > Probably some imports need to be declared in the NAMESPACE file. > > > It's only occurred recently and I have no idea what might have caused > the change. The function proto is from the proto package which does > not have a namespace. > > Thanks, > > Hadley > > > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel