Re: [Rd] Apply .Rbuildignore before copying files in R CMD build

2024-08-28 Thread Kevin Ushey
Hi Alexey, It's kind of gross, but if you need a local solution, you could put your own executable `cp` script on your PATH somewhere, and have that do something "smart" when it's invoked by R. One way to detect that would be to check if the `R_CMD` environment variable is set. For example: https

Re: [Rd] API for converting LANGSXP to LISTSXP?

2024-07-07 Thread Kevin Ushey
; thanks. On Sat, Jul 6, 2024 at 8:09 PM Ivan Krylov wrote: > > On Fri, 5 Jul 2024 15:27:50 +0800 > Kevin Ushey wrote: > > > A common idiom in the R sources is to convert objects between LANGSXP > > and LISTSXP by using SET_TYPEOF. However, this is soon going to be &g

[Rd] API for converting LANGSXP to LISTSXP?

2024-07-05 Thread Kevin Ushey
Hi, A common idiom in the R sources is to convert objects between LANGSXP and LISTSXP by using SET_TYPEOF. However, this is soon going to be disallowed in packages. From what I can see, there isn't currently a direct way to convert between these two object types using the available API. At the R l

Re: [Rd] changes in R-devel and zero-extent objects in Rcpp

2024-06-08 Thread Kevin Ushey
IMHO, this should be changed in both Rcpp and downstream packages: 1. Rcpp could check for out-of-bounds accesses in cases like these, and emit an R warning / error when such an access is detected; 2. The downstream packages unintentionally making these out-of-bounds accesses should be fixed to a

Re: [Rd] [External] Re: Is ALTREP "non-API"?

2024-04-25 Thread Kevin Ushey
On Thu, Apr 25, 2024 at 4:24 AM Ivan Krylov via R-devel wrote: > > On Wed, 24 Apr 2024 15:31:39 -0500 (CDT) > luke-tierney--- via R-devel wrote: > > > We would be better off (in my view, not necessarily shared by others > > in R-core) if we could get to a point where: > > > > all entry point

Re: [Rd] [Feature Request] Hide API Key in download.file() / R's libcurl

2024-02-04 Thread Kevin Ushey
For cases like these, I think it would be more useful to have some mechanism for associating URLs / hosts with credentials, and have R use those credentials by default whenever accessing those URLs. Since download.file() now supports custom headers, this could be a mechanism for setting headers to

Re: [Rd] 答复: R-4.3 version list.files function could not work correctly in chinese

2023-08-14 Thread Kevin Ushey
Just to rule it out... is it possible that R is listing these files successfully, but is not printing the Chinese characters in those names for some reason? Using your example, what is the output of: f <- list.files(a, recursive = T) nchar(f) Does the reported number of characters match

Re: [Rd] Multiple Assignment built into the R Interpreter?

2023-03-11 Thread Kevin Ushey
FWIW, it's possible to get fairly close to your proposed semantics using the existing metaprogramming facilities in R. I put together a prototype package here to demonstrate: https://github.com/kevinushey/dotty The package exports an object called `.`, with a special `[<-.dot` S3 method which

Re: [Rd] Unnecessary note when import only used in arg definition

2023-02-06 Thread Kevin Ushey
Hi Antoine, Maybe I'm misunderstanding, but I think the warning is saying that you've declared the package dependency in the DESCRIPTION file, but you haven't actually imported the package (or any functions) in your package NAMESPACE file? I put together an example package that I think satisfies

Re: [Rd] String interpolation [Was: string concatenation operator (revisited)]

2021-12-07 Thread Kevin Ushey
For what it's worth, you can also get 90% of the way there with: f <- glue::glue f("if you squint, this is a Python f-string") Having this in an add-on package also makes it much easier to change in response to user feedback; R packages have more freedom to make backwards-incompatible cha

Re: [Rd] Inconsistent is.list results on 'by' objects

2021-11-16 Thread Kevin Ushey
You can see this a bit more clearly with e.g. > storage.mode(byy) [1] "list" > storage.mode(byy.empty) [1] "logical" So even though both objects have S3 class "by", they have a different underlying internal storage mode (as simplifying the result of 'by' has given you a 0-length logical, instead

Re: [Rd] R-devel (r81196) hanging at dchisq(large) (PR#13309)

2021-11-16 Thread Kevin Ushey
Do you see this same hang in a build of R with debug symbols? Can you try running R with GDB, or even WinDbg or another debugger, to see what the call stack looks like when the hang occurs? Does the hang depend on the number of threads used by OpenBLAS? On the off chance it's relevant, I've seen h

[Rd] small typo in internet.c

2021-06-12 Thread Kevin Ushey
Hello, I spotted a small typo recently in R-devel: $ rg "htto://" src/modules/internet/internet.c 95: warning(_("the 'wininet' method of url() is deprecated for htto:// and https:// URLs")); I suspect 'htto://' should read 'http://'. Thanks, Kevin __

Re: [Rd] Corrupt internal row names when creating a data.frame with `attributes<-`

2021-02-16 Thread Kevin Ushey
Strictly speaking, I don't think this is a "corrupt" representation, given that any APIs used to access that internal representation will call abs() on the row count encoded within. At least, as far as I can tell, there aren't any adverse downstream effects from having the row names attribute encod

Re: [Rd] the pipe |> and line breaks in pipelines

2020-12-09 Thread Kevin Ushey
I agree with Duncan that the right solution is to wrap the pipe expression with parentheses. Having the parser treat newlines differently based on whether the session is interactive, or on what type of operator happens to follow a newline, feels like a pretty big can of worms. I think this (or som

Re: [Rd] New pipe operator

2020-12-07 Thread Kevin Ushey
IMHO the use of anonymous functions is a very clean solution to the placeholder problem, and the shorthand lambda syntax makes it much more ergonomic to use. Pipe implementations that crawl the RHS for usages of `.` are going to be more expensive than the alternatives. It is nice that the `|>` oper

Re: [Rd] `basename` and `dirname` change the encoding to "UTF-8"

2020-06-29 Thread Kevin Ushey
Did you test with R 4.0.2 or R-devel? A bug related to this issue was recently fixed: https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17833 Best, Kevin On Mon, Jun 29, 2020 at 11:51 AM Duncan Murdoch wrote: > > On 29/06/2020 10:39 a.m., Johannes Rauh wrote: > > Dear R Developers, > > > > I

Re: [Rd] Possible Bug: file.exists() Function. Due to UTF-8 Encoding differences on Windows between R 4.0.1 and R 3.6.3?

2020-06-10 Thread Kevin Ushey
Hi Juan, For bug reports to R, you should attempt to create a minimally-reproducible example, using only R's builtin facilities and not any other addon packages. Given your report, it's not clear whether the issue lies within renv or truly is caused by a change in R 4.0.0. Also note that you have

Re: [Rd] Rtools and R 4.0.0?

2020-04-07 Thread Kevin Ushey
That's great to see, although I suspect it's still a speculative change and could be backed out if any non-trivial issues were encountered. Regardless, I would like to thank R core, CRAN, and Jeroen for all of the time that has gone into creating and validating this new toolchain. This is arduous

[Rd] Rtools and R 4.0.0?

2020-04-01 Thread Kevin Ushey
Hello, Has a decision been made yet as to whether R 4.0.0 on Windows is going to be built using the new gcc8 toolchain (described at https://cran.r-project.org/bin/windows/testing/rtools40.html)? >From the sidelines, I can see that the toolchain is being used to build and test packages on CRAN; i

Re: [Rd] [External] Re: should base R have a piping operator ?

2019-10-07 Thread Kevin Ushey
IMHO, if base R were to include a pipe operator, I think it should be much simpler than the magrittr pipe. It should satisfy the property that: x |> f(...) is equivalent to f(x, ...) Except, perhaps, in terms of when the promise for 'x' gets forced. We shouldn't need to mess with bindings

Re: [Rd] ?Syntax wrong about `?`'s precedence ?

2019-08-30 Thread Kevin Ushey
See also: https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16710 On Fri, Aug 30, 2019 at 9:02 AM William Dunlap via R-devel wrote: > > Precedence is a property of the parser and has nothing to do with the > semantics assigned to various symbols. Using just core R functions you can > see the p

Re: [Rd] Possible bug in `class<-` when a class-specific '[[.' method is defined

2019-07-15 Thread Kevin Ushey
When RStudio builds the Environment pane, it will evaluate some R code on objects in your global environment (as you have seen). In particular, for better or worse, it calls `str()` on objects in the global environment, to get a short text summary of the object. So, to reproduce what you're seeing

Re: [Rd] Fast way to call an R function from C++?

2019-06-18 Thread Kevin Ushey
Hi Jiefei, Calling into R from C++ code is more complicated than one might think. Please see Tomas Kalibera's post here: https://developer.r-project.org/Blog/public/2019/03/28/use-of-c---in-packages/index.html The Rcpp Function class is more expensive than a regular Rf_eval() because it tries to

Re: [Rd] Converting non-32-bit integers from python to R to use bit64: reticulate

2019-06-04 Thread Kevin Ushey
I think a more productive conversation could be: what additions to R would allow for user-defined types / classes that behave just like the built-in vector types? As a motivating example, one cannot currently use the 64bit integer objects from bit64 to subset data frames: > library(bit64); mtca

Re: [Rd] SUGGESTION: Settings to disable forked processing in R, e.g. parallel::mclapply()

2019-04-12 Thread Kevin Ushey
I think it's worth saying that mclapply() works as documented: it relies on forking, and so doesn't work well in environments where it's unsafe to fork. This is spelled out explicitly in the documentation of ?mclapply: It is strongly discouraged to use these functions in GUI or embedded environmen

Re: [Rd] Use of C++ in Packages

2019-03-29 Thread Kevin Ushey
I think it's also worth saying that some of these issues affect C code as well; e.g. this is not safe: FILE* f = fopen(...); Rf_eval(...); fclose(f); whereas the C++ equivalent would likely handle closing of the file in the destructor. In other words, I think many users just may not b

Re: [Rd] Objectsize function visiting every element for alt-rep strings

2019-01-22 Thread Kevin Ushey
I think that object.size() is most commonly used to answer the question, "what R objects are consuming the most memory currently in my R session?" and for that reason I think returning the size of the internal representations of objects (for e.g. ALTREP objects; unevaluated promises) is the right d

Re: [Rd] methods(class = class()) - improve for |cl.| > 1 ?

2018-10-19 Thread Kevin Ushey
I think this would be a good change. I think most users use the 'methods(class = <...>)' function to answer the question, "what methods can I call on objects with these classes?", and in that context I think it would be sensible for the function to accept more than one class. Kevin On Wed, Oct 17

Re: [Rd] Bug when calling system/system2 (and request for Bugzilla account)

2018-09-14 Thread Kevin Ushey
FWIW I can reproduce on macOS with R 3.5.1. A smaller example: system2("ls", timeout = 5); x <- sample(1:1E8) If I try to interrupt R while that sample call is running, R itself is closed. Best, Kevin On Fri, Sep 14, 2018 at 10:53 AM Emil Bode wrote: > > I hope it's not too specific in my

Re: [Rd] True length - length(unclass(x)) - without having to call unclass()?

2018-09-05 Thread Kevin Ushey
More generally, I think one of the issues is that R is not yet able to decrement a reference count (or mark a 'shared' data object as 'unshared' after it knows only one binding to it exists). This means passing variables to R closures will mark that object as shared: x <- list() .Internal(

Re: [Rd] Output mis-encoded on Windows w/ RGui 3.5.1 in strange case

2018-07-18 Thread Kevin Ushey
mas Kalibera wrote: > > Thanks, I can now reproduce and it is a bug that is easy to fix, I will do so > shortly. > > Fyi it can be reproduced simply by running these two lines in Rgui: > > list() > encodeString("apple") > > Best > Tomas > > On 07/17/2

Re: [Rd] Output mis-encoded on Windows w/ RGui 3.5.1 in strange case

2018-07-17 Thread Kevin Ushey
the escapes on R-devel. Please clarify the > example if you believe it is a bug. Please also use current R-devel > (I've relatively recently fixed a bug in decoding these escaped strings, > perhaps unlikely, but not impossible it could be related). > > Best > Tomas > > O

[Rd] Output mis-encoded on Windows w/ RGui 3.5.1 in strange case

2018-07-16 Thread Kevin Ushey
Given the following R script: x <- 1 print(list()) save(x, file = tempfile()) output <- encodeString("apple") print(output) If I source this script from RGui on Windows, I see the output: > source("encoding.R") list() [1] "\002ÿþapple\003ÿþ" That is, it's as though R has

Re: [Rd] writeLines argument useBytes = TRUE still making conversions

2018-02-17 Thread Kevin Ushey
Of course, right after writing this e-mail I tested on my Windows machine and did not see what I expected: > charToRaw(before) [1] c3 a9 > charToRaw(after) [1] e9 so obviously I'm misunderstanding something as well. Best, Kevin On Sat, Feb 17, 2018 at 2:19 PM, Kevin Ushey wrote

Re: [Rd] writeLines argument useBytes = TRUE still making conversions

2018-02-17 Thread Kevin Ushey
before <- iconv('é', to = "UTF-8") cat(before, file = conn, sep = "\n") after <- readLines(conn) charToRaw(before) charToRaw(after) with output: > charToRaw(before) [1] c3 a9 > charToRaw(after) [1] c3 a9 Best, Kevin

Re: [Rd] writeLines argument useBytes = TRUE still making conversions

2018-02-15 Thread Kevin Ushey
I suspect your UTF-8 string is being stripped of its encoding before write, and so assumed to be in the system native encoding, and then re-encoded as UTF-8 when written to the file. You can see something similar with: > tmp <- 'é' > tmp <- iconv(tmp, to = 'UTF-8') > Encoding(tmp) <- "

Re: [Rd] Bug: Issues on Windows with SFN disabled

2017-12-08 Thread Kevin Ushey
For what it's worth, the Windows installers for other programming language runtimes often install outside of Program Files, so at least there is 'prior art' to motivate having R install directly into the root of the home drive: - ActiveState Perl installs directly C:/Perl; - Python install

Re: [Rd] unlicense

2017-01-17 Thread Kevin Ushey
The Free Software Foundation maintains a list of free and GPL-compatible software licenses here: https://www.gnu.org/licenses/license-list.en.html#Unlicense It appears that Unlicense is considered a free and GPL-compatible license; however, the page does suggest using CC0 instead (which is indeed

Re: [Rd] require(..., quietly=TRUE) does not suppress warning

2016-12-08 Thread Kevin Ushey
IMHO the strongest argument for suppressing the warning message here is the fact that requireNamespace("foo", quietly = TRUE) does not emit any warning message when the package 'foo' does not exist. On Thu, Dec 8, 2016 at 12:51 PM, Dan Tenenbaum wrote: > Well, I'm getting a warning (not an

Re: [Rd] creating a long list puts R in a state where many things stop working

2016-11-15 Thread Kevin Ushey
For reference, running your code in a build of R-devel with sanitizers: > x <- vector(mode="list", length=3e9) memory.c:2747:27: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'R_len_t' (aka 'int') SUMMARY: AddressSanitizer: undefined-behavior memory.c:2747:27

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

2016-10-24 Thread Kevin Ushey
Hi R-devel, One of the more common issues that new R users see, and become stumped by, is error messages during package load of the form: > library(ggplot2) Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : there is no package called 'Rcpp' Error: package o

Re: [Rd] strange behavior in 'inherits' check for loaded S4 object

2016-08-02 Thread Kevin Ushey
it owned the function or some of the > classes.) > > R could adopt a different model for generic functions, where a package that > defined a method for a non-exported class would create a "local" version of > the generic, but that would likely raise some other issues. &g

Re: [Rd] strange behavior in 'inherits' check for loaded S4 object

2016-07-29 Thread Kevin Ushey
namespace: digest > methods:::.requirePackage("digest") > "digest" %in% loadedNamespaces() [1] TRUE > "package:digest" %in% search() [1] FALSE This may be intentional, but the behavior seems surprising and could be responsible for the behav

Re: [Rd] strange behavior in 'inherits' check for loaded S4 object

2016-07-29 Thread Kevin Ushey
age's namespace, not within the package environment, it is not resolved, and so lookup fails. (Presumedly, that lookup is done when initially building a cache for S3 dispatch?) So, I wonder if that class lookup should occur within the package's namespace instead? Thanks for your time,

Re: [Rd] package installation fails when symlink of same name exists

2016-07-20 Thread Kevin Ushey
On Wed, Jul 20, 2016 at 3:52 AM, Martin Maechler wrote: >>>>>> Jeroen Ooms >>>>>> on Wed, 20 Jul 2016 10:26:19 +0200 writes: > > > On Tue, Jul 19, 2016 at 6:46 PM, Kevin Ushey > wrote: > >> R fails to install a package from

[Rd] package installation fails when symlink of same name exists

2016-07-19 Thread Kevin Ushey
R fails to install a package from source over a pre-existing package when the path to that package is a symlink, rather than a directory. A reproducible example to illustrate (using MASS as an example): # create a temporary R library in tempdir library <- tempfile() if (!dir.exists(lib

[Rd] strange behavior in 'inherits' check for loaded S4 object

2016-06-25 Thread Kevin Ushey
Hi, (sorry for the wall of text; the issue here appears to be rather complicated) I'm seeing a somewhat strange case where checking whether an S4 object inherits from a parent class defined from another package with 'inherits' fails if that object is materialized through a call to 'load'. That's

Re: [Rd] Issues with libcurl + HTTP status codes (eg. 403, 404)

2015-08-27 Thread Kevin Ushey
Thanks for looking into this so promptly! Should users expect the behaviour to be congruent across all of the supported external programs (curl, wget) as well? E.g. URL <- "http://cran.rstudio.org/no/such/file/here.tar.gz"; download <- function(file, method, ...) print(download.file

Re: [Rd] Issues with libcurl + HTTP status codes (eg. 403, 404)

2015-08-25 Thread Kevin Ushey
that R-core is aware of. Thanks, and apologies again for the spam, Kevin On Tue, Aug 25, 2015 at 2:41 PM, Kevin Ushey wrote: > In fact, this does reproduce on R-devel: > > > options(download.file.method = "libcurl") > > options(repos = c(CRAN = "https

Re: [Rd] Issues with libcurl + HTTP status codes (eg. 403, 404)

2015-08-25 Thread Kevin Ushey
s unspecified) Error in install.packages : Line starting 'https://cran.fhcrc.org`. Kevin On Tue, Aug 25, 2015 at 1:33 PM, Martin Morgan wrote: > On 08/25/2015 01:30 PM, Kevin Ushey wrote: >> >> Hi Martin, >> >> Indeed it does (and I should have confirmed myself w

Re: [Rd] Issues with libcurl + HTTP status codes (eg. 403, 404)

2015-08-25 Thread Kevin Ushey
Hi Martin, Indeed it does (and I should have confirmed myself with R-patched and R-devel before posting...) Thanks, and sorry for the noise. Kevin On Tue, Aug 25, 2015, 13:11 Martin Morgan wrote: > On 08/25/2015 12:54 PM, Kevin Ushey wrote: > > Hi all, > > > > The follo

[Rd] Issues with libcurl + HTTP status codes (eg. 403, 404)

2015-08-25 Thread Kevin Ushey
Hi all, The following fails for me (on OS X, although I imagine it's the same on other platforms using libcurl): options(download.file.method = "libcurl") options(repos = c(CRAN = "https://cran.rstudio.com/";, CRANextra = "http://www.stats.ox.ac.uk/pub/RWin";)) install.packages("latti

Re: [Rd] R package with Fortran module on Windows? undefined reference to `__stack_chk_fail'

2015-07-27 Thread Kevin Ushey
You should be able to set PKG_FCFLAGS="-fno-stack-protector" when compiling to ensure that the stack protector is not used. (Trying that out on a Windows VM, with a simple `R CMD build` + `R CMD INSTALL`, compilation of your package succeeded but linking failed saying the DLL 'Fpi' was not found;

Re: [Rd] bquote/evalq behavior changed in R-3.2.1

2015-07-15 Thread Kevin Ushey
My best guess is that it could be related to this commit: https://github.com/wch/r-source/commit/14f904c32a44010d4dfb8a829805648a88c22f53, since that's the only change that's touched `rapply` lately. On Wed, Jul 15, 2015 at 12:35 PM, Dayne Filer wrote: > In 3.1.2 eval does not store the result of

Re: [Rd] NEWS.md support on CRAN

2015-05-24 Thread Kevin Ushey
I like the idea of supporting a small, strict subset of Markdown that can be used to translate from NEWS.md to NEWS. Following from Yihui's example, it would be pretty easy to write a parser in R for such a format (and I'd be willing to try implementing one, if that would be of interest). Kevin

Re: [Rd] Installation error with R-devel

2015-05-15 Thread Kevin Ushey
It's hard to diagnose this without your package sources / a reproducible example. Shot in the dark: one thing worth checking is that you don't have an entry in your `.Rbuildignore` that's removing files you don't expect it to (maybe that's causing R to strip out the 'doc/index.html' file) Kevin

Re: [Rd] Reading exit code of pipe()

2015-05-13 Thread Kevin Ushey
Hi Jeroen, I think `pipe` might just be returning the status code of the underlying command executed; for example, I get a status code of '0' when I test a pipe on `ls`: conn <- pipe("ls") stream <- readLines(conn) print(close(conn)) Similarly, I get an error code if I try to `ls` a

Re: [Rd] Alternative for wildcard gnu extension in Makevars

2015-05-13 Thread Kevin Ushey
One other solution that's only a little crazy: you could have a R function within your package that generates the appropriate (portable) Makevars, and within the package `configure` script call that function. For example" R --vanilla --slave -e "source('R/makevars.R'); makevars()" And that 'm

Re: [Rd] Inconsistency when naming a vector

2015-04-27 Thread Kevin Ushey
In `?names`: If ‘value’ is shorter than ‘x’, it is extended by character ‘NA’s to the length of ‘x’. So it is as documented. That said, it's somewhat surprising that both NA and "" serve as a placeholder for a 'missing name'; I believe they're treated identically by R under the hood (e

Re: [Rd] [PATCH] Makefile: add support for git svn clones

2015-01-19 Thread Kevin Ushey
On Mon, Jan 19, 2015 at 12:34 PM, Felipe Balbi wrote: > Hi, > > On Mon, Jan 19, 2015 at 03:31:32PM -0500, Duncan Murdoch wrote: >> >>> git has an interface for cloning SVN repositories into git >> >>> which some users might decide to use. For those users' >> >>> surprise, the repository will alway

Re: [Rd] subscripting a data.frame (without changing row order) changes internal row.names

2014-11-10 Thread Kevin Ushey
I believe the question here is related to the sign on the compact row names representation: why is it sometimes `c(NA, )` and sometimes `c(NA, )` -- why the difference in sign? To the best of my knowledge, older versions of R used the signed-ness of compact row.names to differentiate between diffe

[Rd] R's internal tar ignores files in sub-directories

2014-09-30 Thread Kevin Ushey
E.g. I am seeing: dir <- file.path(tempdir(), "test-tar") dir.create(dir) setwd(dir) dir.create("foo", showWarnings = FALSE) file.create("foo/bar.R") tar("test.tar", files = "foo/bar.R") dir.create("untarred") untar("test.tar", exdir = "untarred") list.files("

[Rd] Bug in new behaviour for all.equal and environments?

2014-09-21 Thread Kevin Ushey
Hi R-devel, The following code: all.equal(baseenv(), baseenv()) gives the error when run in a clean R session with latest R-devel (r66650): kevin:~$ R --vanilla --slave -e "all.equal(baseenv(), baseenv())" Error in all.equal.envRefClass(target[[i]], current[[i]], check.attributes =

Re: [Rd] vignette index going AWOL

2014-08-25 Thread Kevin Ushey
Hi Randall, I notice that, in your .Rbuildignore, you have the entry: ^build$ and I suspect this is the culprit (having being bitten by a similar problem before). Some part of the R build / install process creates / uses that directory, but having it excluded in .Rbuildignore will cause you

[Rd] Removed 'extern' on R_running_as_main_program in Rinterface.h -- intentional?

2014-07-22 Thread Kevin Ushey
Hi R-devel, In this commit: https://github.com/wch/r-source/commit/c67a107dd7b0f074cec9359b8e2ca07c6243283c R_running_as_main_program was moved from Rmain.c to Rinterface.h, and lost its 'extern' declaration. This change is causing us linker problems (since we now have duplicate symbols for R_run

[Rd] USE_CXX1X, Snow Leopard R binaries + Mavericks

2014-07-01 Thread Kevin Ushey
Hi R-devel, I'm noticing the following behaviour: writeLines("#include ", file = "test.cpp") Rcpp::sourceCpp("~/test.cpp") ## succeeds at trivial compile Sys.setenv("USE_CXX1X" = "yes") Rcpp::sourceCpp("~/test.cpp") ## fails; CXX nor CXX1X properly set (?) IIUC, R is not propagat

Re: [Rd] operation on ‘numsels’ may be undefined

2014-06-24 Thread Kevin Ushey
e into the language lawyer land of C/C++ standards, so let's all just agree that, regardless of what the correct interpretation is, 'i = i++' and 'i = ++i' are just things you shouldn't write :) Cheers, Kevin On Tue, Jun 24, 2014 at 3:38 PM, Hervé Pagès wrote

Re: [Rd] Curious behavior of $ and lapply

2014-06-23 Thread Kevin Ushey
`lapply` basically takes its call and massages into calls of the following form: FUN(X[[1L]], ...) FUN(X[[2L]], ...) ... that get evaluated in the appropriate environment. For `lapply(list(list(a=3,b=4)),"$","b")`, you can imagine that a function `FUN` of the form: FUN <- funct

Re: [Rd] operation on ‘numsels’ may be undefined

2014-06-23 Thread Kevin Ushey
I don't see what's so surprising here. That statement is identical to writing: if (arrMask[i] == 1) { numsels = ++numsels; } else { numsels = numsels; } and numsels = ++numsels; has two statements modifying the value of numsels (= and prefix-++) in a single sequ

Re: [Rd] How to test if an object/argument is "parse tree" - without evaluating it?

2014-05-01 Thread Kevin Ushey
Henrik, If I understand correctly, you want something along the lines of (following your example): foo <- function(expr) { if (!is.language(expr)) substitute(expr) else expr } ## first example expr0 <- foo({ x <- 1 }) expr1 <- foo(expr0) stopifnot(identical(ex

[Rd] Is it possible to shrink an R object in place?

2014-04-10 Thread Kevin Ushey
Suppose I generate an integer vector with e.g. SEXP iv = PROTECT(allocVector(INTSXP, 100)); and later want to shrink the object, e.g. shrink(iv, 50); would simply re-set the length to 50, and allow R to reclaim the memory that was previously used. Is it possible to do this while respec

Re: [Rd] C API to get numrow of data frame

2014-03-31 Thread Kevin Ushey
The safest way is to check the length of the row.names attribute, e.g. length(getAttrib(df, R_RowNamesSymbol)). This protects you from both data.frames with zero columns, as well as corrupted data.frames containing columns with different lengths, since by definition the number of rows in a da

Re: [Rd] internal string comparison (Scollate)

2014-03-27 Thread Kevin Ushey
I too think it would be useful if R exported some version of its string sorting routines, since sorting strings while respecting locale, and doing so in a portable fashion while respecting the user's environment, is not trivial. R holds a fast, portable, well-tested solution, and I think package de

Re: [Rd] Question re: NA, NaNs in R

2014-02-10 Thread Kevin Ushey
2_set(y,a,b)\ >>> if (ISNA (a) || ISNA (b)) y = NA_REAL;\ >>> else if (ISNAN(a) || ISNAN(b)) y = R_NaN; >>> >>> Other R functions, like the basic arithmetic operations +-/*^, >>> do not (search for PLUSOP in src/main/arithm

Re: [Rd] Question re: NA, NaNs in R

2014-02-10 Thread Kevin Ushey
ike the basic arithmetic operations +-/*^, >> do not (search for PLUSOP in src/main/arithmetic.c). >> They just let the hardware do the calculations. >> As a result, you can get odd results like >> > is.nan(NA_real_ + NaN) >> [1] FALSE >> > is.nan(NaN + NA_re

Re: [Rd] Question re: NA, NaNs in R

2014-02-10 Thread Kevin Ushey
e R help files help(is.na) and help(is.nan) suggest that > computations involving NA and NaN are indeterminate. > > It is faster to use the R convention; most operations are just > handled by the hardware, without extra work. > > In cases like sum(x, na.rm=TRUE), the help file specifies that b

[Rd] Question re: NA, NaNs in R

2014-02-09 Thread Kevin Ushey
Hi R-devel, I have a question about the differentiation between NA and NaN values as implemented in R. In arithmetic.c, we have int R_IsNA(double x) { if (isnan(x)) { ieee_double y; y.value = x; return (y.word[lw] == 1954); } return 0; } ieee_double is just used for type punning so w

Re: [Rd] Format an empty data frame

2014-01-24 Thread Kevin Ushey
This behaviour is fixed in R-devel (tested with r64727) > format( data.frame() ) data frame with 0 columns and 0 rows -Kevin On Thu, Jan 23, 2014 at 11:59 PM, Yihui Xie wrote: > Hi, > > Here seems to be a corner case in which format() fails: > >> format(data.frame()) > Error in .subset2(x, i, e

Re: [Rd] Question about writing portable packages

2013-06-07 Thread Kevin Ushey
I think the key word here is _other_ packages. It's entirely okay to call your package's own compiled code through the .Call interface (and the code you write may link to other packages; the obvious example being Rcpp code you write); however, it is not portable to use .Call to call compiled code f