Re: [Rd] can we override "if" in R?

2017-03-05 Thread Da Zheng
On Sun, Mar 5, 2017 at 2:50 PM, Michael Lawrence
<lawrence.mich...@gene.com> wrote:
>
>
> On Sat, Mar 4, 2017 at 12:36 PM, Da Zheng <zhengda1...@gmail.com> wrote:
>>
>> In my case, I create a new type of matrices and override matrix
>> operations in R for these matrices.
>> My goal is to make the system as transparent as possible, which means
>> my system should execute the existing R code without modification.
>> The problem is that when data is in my own vectors or matrices, "if"
>> or "while" can't access their values unless we explicitly convert them
>> into R objects. But this means users need to modify the existing code.
>> So I hope I can override "if", "while", etc to access data in my own
>> vectors and matrices directly.
>> Does this sound reasonable?
>>
>
> Would you really need the alternate representation for scalar logicals?
>
> I can see a case in the deferred evaluation context, although it would be
> problematic wrt side effects unless the deferral is complete.
This is exactly why I want to use my own matrix objects and redefine
"if" for the matrices. In my framework, all matrices are read-only, so
there isn't side effect.

Best,
Da
>
>
>
>>
>> Best,
>> Da
>>
>> On Sat, Mar 4, 2017 at 3:22 PM, Michael Lawrence
>> <lawrence.mich...@gene.com> wrote:
>> > I'm curious as to precisely why someone would want to do this.
>> >
>> > On Sat, Mar 4, 2017 at 11:49 AM, Da Zheng <zhengda1...@gmail.com> wrote:
>> >>
>> >> I'm just curious. Why making "if" generic is even more dangerous?
>> >>
>> >> Best,
>> >> Da
>> >>
>> >> On Sat, Mar 4, 2017 at 1:22 PM, Gábor Csárdi <csardi.ga...@gmail.com>
>> >> wrote:
>> >> > `!` is a generic, `if` is not. You can define an `if` that is
>> >> > generic,
>> >> > but this might be even more dangerous
>> >> >
>> >> > ❯ `if` <- function(a, b, c) UseMethod("if")
>> >> > ❯ `if.default` <- function(a,b,c) base::`if`(a, b, c)
>> >> > ❯ `if.foo` <- function(a, b, c) FALSE
>> >> > ❯ a <- structure(42, class = "foo")
>> >> >
>> >> > ❯ if (a) TRUE else FALSE
>> >> > [1] FALSE
>> >> >
>> >> > ❯ if (1) TRUE else FALSE
>> >> > [1] TRUE
>> >> >
>> >> > Gabor
>> >> >
>> >> > On Sat, Mar 4, 2017 at 5:47 PM, Da Zheng <zhengda1...@gmail.com>
>> >> > wrote:
>> >> >> Thanks.
>> >> >> Can I override it for a specific class?
>> >> >> I can do that for operators such as "!". For example, "!.fm" works
>> >> >> for
>> >> >> objects of the class "fm".
>> >> >> It seems I can't do the same for "if".
>> >> >>
>> >> >> Best,
>> >> >> Da
>> >> >>
>> >> >> On Sat, Mar 4, 2017 at 12:41 PM, Gábor Csárdi
>> >> >> <csardi.ga...@gmail.com>
>> >> >> wrote:
>> >> >>> You can. Perhaps needless to say, be careful with this.
>> >> >>>
>> >> >>> ❯ `if` <- function(...) FALSE
>> >> >>> ❯ if (TRUE) TRUE else FALSE
>> >> >>> [1] FALSE
>> >> >>>
>> >> >>> G.
>> >> >>>
>> >> >>> On Sat, Mar 4, 2017 at 5:36 PM, Da Zheng <zhengda1...@gmail.com>
>> >> >>> wrote:
>> >> >>>> Hello,
>> >> >>>>
>> >> >>>> I heard we can override almost everything in R. Is it possible to
>> >> >>>> override "if" keyword in R to evaluate my own object instead of a
>> >> >>>> logical value?
>> >> >>>>
>> >> >>>> Thanks,
>> >> >>>> Da
>> >> >>>>
>> >> >>>> __
>> >> >>>> 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
>> >
>> >
>
>

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Re: [Rd] can we override "if" in R?

2017-03-04 Thread Da Zheng
In my case, I create a new type of matrices and override matrix
operations in R for these matrices.
My goal is to make the system as transparent as possible, which means
my system should execute the existing R code without modification.
The problem is that when data is in my own vectors or matrices, "if"
or "while" can't access their values unless we explicitly convert them
into R objects. But this means users need to modify the existing code.
So I hope I can override "if", "while", etc to access data in my own
vectors and matrices directly.
Does this sound reasonable?

Best,
Da

On Sat, Mar 4, 2017 at 3:22 PM, Michael Lawrence
<lawrence.mich...@gene.com> wrote:
> I'm curious as to precisely why someone would want to do this.
>
> On Sat, Mar 4, 2017 at 11:49 AM, Da Zheng <zhengda1...@gmail.com> wrote:
>>
>> I'm just curious. Why making "if" generic is even more dangerous?
>>
>> Best,
>> Da
>>
>> On Sat, Mar 4, 2017 at 1:22 PM, Gábor Csárdi <csardi.ga...@gmail.com>
>> wrote:
>> > `!` is a generic, `if` is not. You can define an `if` that is generic,
>> > but this might be even more dangerous
>> >
>> > ❯ `if` <- function(a, b, c) UseMethod("if")
>> > ❯ `if.default` <- function(a,b,c) base::`if`(a, b, c)
>> > ❯ `if.foo` <- function(a, b, c) FALSE
>> > ❯ a <- structure(42, class = "foo")
>> >
>> > ❯ if (a) TRUE else FALSE
>> > [1] FALSE
>> >
>> > ❯ if (1) TRUE else FALSE
>> > [1] TRUE
>> >
>> > Gabor
>> >
>> > On Sat, Mar 4, 2017 at 5:47 PM, Da Zheng <zhengda1...@gmail.com> wrote:
>> >> Thanks.
>> >> Can I override it for a specific class?
>> >> I can do that for operators such as "!". For example, "!.fm" works for
>> >> objects of the class "fm".
>> >> It seems I can't do the same for "if".
>> >>
>> >> Best,
>> >> Da
>> >>
>> >> On Sat, Mar 4, 2017 at 12:41 PM, Gábor Csárdi <csardi.ga...@gmail.com>
>> >> wrote:
>> >>> You can. Perhaps needless to say, be careful with this.
>> >>>
>> >>> ❯ `if` <- function(...) FALSE
>> >>> ❯ if (TRUE) TRUE else FALSE
>> >>> [1] FALSE
>> >>>
>> >>> G.
>> >>>
>> >>> On Sat, Mar 4, 2017 at 5:36 PM, Da Zheng <zhengda1...@gmail.com>
>> >>> wrote:
>> >>>> Hello,
>> >>>>
>> >>>> I heard we can override almost everything in R. Is it possible to
>> >>>> override "if" keyword in R to evaluate my own object instead of a
>> >>>> logical value?
>> >>>>
>> >>>> Thanks,
>> >>>> Da
>> >>>>
>> >>>> __
>> >>>> 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
>
>

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Re: [Rd] can we override "if" in R?

2017-03-04 Thread Da Zheng
I'm just curious. Why making "if" generic is even more dangerous?

Best,
Da

On Sat, Mar 4, 2017 at 1:22 PM, Gábor Csárdi <csardi.ga...@gmail.com> wrote:
> `!` is a generic, `if` is not. You can define an `if` that is generic,
> but this might be even more dangerous
>
> ❯ `if` <- function(a, b, c) UseMethod("if")
> ❯ `if.default` <- function(a,b,c) base::`if`(a, b, c)
> ❯ `if.foo` <- function(a, b, c) FALSE
> ❯ a <- structure(42, class = "foo")
>
> ❯ if (a) TRUE else FALSE
> [1] FALSE
>
> ❯ if (1) TRUE else FALSE
> [1] TRUE
>
> Gabor
>
> On Sat, Mar 4, 2017 at 5:47 PM, Da Zheng <zhengda1...@gmail.com> wrote:
>> Thanks.
>> Can I override it for a specific class?
>> I can do that for operators such as "!". For example, "!.fm" works for
>> objects of the class "fm".
>> It seems I can't do the same for "if".
>>
>> Best,
>> Da
>>
>> On Sat, Mar 4, 2017 at 12:41 PM, Gábor Csárdi <csardi.ga...@gmail.com> wrote:
>>> You can. Perhaps needless to say, be careful with this.
>>>
>>> ❯ `if` <- function(...) FALSE
>>> ❯ if (TRUE) TRUE else FALSE
>>> [1] FALSE
>>>
>>> G.
>>>
>>> On Sat, Mar 4, 2017 at 5:36 PM, Da Zheng <zhengda1...@gmail.com> wrote:
>>>> Hello,
>>>>
>>>> I heard we can override almost everything in R. Is it possible to
>>>> override "if" keyword in R to evaluate my own object instead of a
>>>> logical value?
>>>>
>>>> Thanks,
>>>> Da
>>>>
>>>> __
>>>> 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] can we override "if" in R?

2017-03-04 Thread Da Zheng
Thanks.
Can I override it for a specific class?
I can do that for operators such as "!". For example, "!.fm" works for
objects of the class "fm".
It seems I can't do the same for "if".

Best,
Da

On Sat, Mar 4, 2017 at 12:41 PM, Gábor Csárdi <csardi.ga...@gmail.com> wrote:
> You can. Perhaps needless to say, be careful with this.
>
> ❯ `if` <- function(...) FALSE
> ❯ if (TRUE) TRUE else FALSE
> [1] FALSE
>
> G.
>
> On Sat, Mar 4, 2017 at 5:36 PM, Da Zheng <zhengda1...@gmail.com> wrote:
>> Hello,
>>
>> I heard we can override almost everything in R. Is it possible to
>> override "if" keyword in R to evaluate my own object instead of a
>> logical value?
>>
>> Thanks,
>> Da
>>
>> __
>> 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

[Rd] can we override "if" in R?

2017-03-04 Thread Da Zheng
Hello,

I heard we can override almost everything in R. Is it possible to
override "if" keyword in R to evaluate my own object instead of a
logical value?

Thanks,
Da

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] cross-platform portable code in CRAN Repository Policy

2017-01-28 Thread Da Zheng
Thank you very much for all your responses. It's very clear to me what I
need to do and what service I should use for testing now.

Thanks,
Da

On Fri, Jan 27, 2017 at 5:40 PM, Henrik Bengtsson <
henrik.bengts...@gmail.com> wrote:

> Second this.  As the CRAN Policies suggests, there's also the very
> handy winbuilder service (https://win-builder.r-project.org/) you can
> use to check your package on Windows.  This service has been a
> valuable workhorse for years.
>
> We should also mention the continuous integration (CI) services
> provided for free by Travis (Linux and macOS) and AppVeyor (Windows)
> in combination with GitHub (or GitLab, ...).  By adding simple
> .travis.yml and appveyor.yml to your Git repos (e.g.
> https://github.com/HenrikBengtsson/globals), they run R CMD check
> --as-cran and covr::package_coverage() etc for you more or less on the
> fly, e.g.
>
> * https://travis-ci.org/HenrikBengtsson/globals
> * https://ci.appveyor.com/project/HenrikBengtsson/globals
>
> /Henrik
>
> PS. Thanks to everyone who made all of the above possible.
>
> On Fri, Jan 27, 2017 at 2:17 PM, Dirk Eddelbuettel <e...@debian.org> wrote:
> >
> > On 27 January 2017 at 21:54, Gábor Csárdi wrote:
> > | On Fri, Jan 27, 2017 at 9:28 PM, Da Zheng <zhengda1...@gmail.com>
> wrote:
> > | > What major R platforms does this policy refer to?
> > | >
> > |
> > | Linux, macOS, Windows.
> > |
> > |
> > | > Currently, my package runs in Ubuntu. If it works on both Ubuntu and
> > | > Redhat, does it count as two platforms?
> > | >
> > |
> > | I think that Linux is just one. Is it hard to make it work on macOS?
> > |
> > | I am not saying that if it is Linux-only then it definitely cannot
> make it
> > | to CRAN.
> > | A CRAN maintainer will decide that.
> >
> > Gabor is *way* too modest here to not mention the *fabulous* tool he has
> > written (with the [financial] support of the R Consortium):  R Hub.
> >
> > These days I just do'rhub::check_for_cran()'   and four tests launch
> > covering the three required OSs as well as the required r-devel and
> r-release
> > versions.  Results tickle in within minutes by mail; the windows one
> (which
> > is slowest) is also display.  You need a one-time token handshake.
> >
> > I strongly recommend the service.
> >
> > Dirk
> >
> > --
> > http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org
> >
> > __
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

[Rd] cross-platform portable code in CRAN Repository Policy

2017-01-27 Thread Da Zheng
Hello,

I'm trying to submit my package to CRAN. When I read the policy, it says:
Package authors should make all reasonable efforts to provide
cross-platform portable code. Packages will not normally be accepted
that do not run on at least two of the major R platforms.

What major R platforms does this policy refer to?
Currently, my package runs in Ubuntu. If it works on both Ubuntu and
Redhat, does it count as two platforms?

Thanks,
Da

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] compile c++ code in an R package without -g

2016-10-16 Thread Da Zheng
Hello Dirk,

Thank you very much for your reply.

The main reason I want to remove the debug info is that when I use R
CMD check on my package, it gives the following info
* checking installed package size ... NOTE
  installed size is 223.6Mb
  sub-directories of 1Mb or more:
  libs 223.1Mb

CRAN requires an R package to pass all checks and fix all complaints
including NOTEs.
It seems R's default compilation options significantly increase the
library size.
Do you have any suggestions on fixing this NOTE?

Thanks,
Da

On Sun, Oct 16, 2016 at 10:09 AM, Dirk Eddelbuettel <e...@debian.org> wrote:
>
> On 16 October 2016 at 09:46, Da Zheng wrote:
> | I'm writing an R package that is mainly written in C++. By default, R
> | CMD INSTALL creates C/C++ flags as follows:
> | -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat
> | -Werror=format-security -D_FORTIFY_SOURCE=2 -g
>
> That looks like you are running R on a Debian or Ubuntu system as these are
> the compilation defaults we set everywhere, and which my r-base-core package
> has via the same defaults.
>
> That is also where the `-g` comes from.  By default we compile everything
> with debugging, and (these days) strip debug symbols away in a -dbg package.
>
> I.e. if you wanted to use gdb to analyse R you could without recompilation by
> just installing the r-base-core-dbg package.  That is a nice feature.
>
> | However, my package is fairly large. With debug info compiled into the
> | library, the generated .so file is over 200MB. Without debug info,
> | it's about 30MB. I hope by default debug info is disabled.
>
> You cannot, currently.
>
> The values in Makeconf (for us in /etc/R/Makeconf) cannot be edited before `R
> CMD INSTALL` et al use them.  That is a pity, but such is life.  We had prior
> discussions about this here; and at least Simon chimed in once and confirmed.
>
> | However, I don't see any option in R CMD INSTALL that can disable
> | "-g". Could  anyone tell me how to disable it?
>
> You cannot, currently.
>
> There are a few ways out:
>
>   i)  Quick local fix: Edit /etc/R/Makeconf. Obviously not portable.
>
>  ii)  Rebuild R without -g in the configure flags. Ditto.
>
> iii)  Do something in src/Makevars to strip after the build.  May be
>   flagged as non-portable by CRAN but at least it tries.
>
>  iv)  (Lot of work, potentially) Patch the R build system to allow, say,
>   sed filtering of some of the values in Makeconf. Get the patch
>   included.
>
> Hope this helps,  Dirk
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] override pmin/pmax for my own matrix

2015-12-24 Thread Da Zheng
Thank you. It works!

On Thu, Dec 24, 2015 at 9:08 AM, Michael Lawrence
<lawrence.mich...@gene.com> wrote:
> Yes, functions like c, min and max are special cases, as they are
> primitives. For ordinary functions, you just need to promote them with
> "..." as the signature:
>
> setGeneric("pmax", signature="...")
> setMethod("pmax", "Class", function(..., na.rm=FALSE) { })
>
> One caveat is that all arguments passed via "..." must derive from the
> class specified for "..." in the method signature. At some point we
> should solve that by introducing a binary pmin2, pmax2 as we have for
> cbind and rbind.
>
>
> On Thu, Dec 24, 2015 at 5:54 AM, Da Zheng <zhengda1...@gmail.com> wrote:
>> Hello,
>>
>> I'm trying to override pmin and pmax for my own matrix. These two
>> functions have ... as an argument. I tried to override them as
>> follows:
>> setMethod("pmax", class_name, function(x, ..., na.rm) { ... })
>>
>> I use this way to override primitive functions such as min/max and it
>> works fine.
>> But it doesn't work for pmin and pmax. I guess because they are
>> regular functions?
>> How do I override a regular function with ... as an argument?
>>
>> Thanks,
>> Da
>>
>> __
>> 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


[Rd] override pmin/pmax for my own matrix

2015-12-24 Thread Da Zheng
Hello,

I'm trying to override pmin and pmax for my own matrix. These two
functions have ... as an argument. I tried to override them as
follows:
setMethod("pmax", class_name, function(x, ..., na.rm) { ... })

I use this way to override primitive functions such as min/max and it
works fine.
But it doesn't work for pmin and pmax. I guess because they are
regular functions?
How do I override a regular function with ... as an argument?

Thanks,
Da

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel