[Rd] Evaluate part of an expression at C level

2019-09-27 Thread Morgan Morgan
Hi,

I am wondering if the below is possible?
Let's assume I have the following expression:

1:10 < 5

Is there a way at the R C API level to only evaluate the 5th element (i.e 5
< 5) instead of evaluating the whole expression and then select the 5th
element in the logical vector?

Thank you
Best regards
Morgan

[[alternative HTML version deleted]]

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


Re: [Rd] Evaluate part of an expression at C level

2019-09-27 Thread Hugh Parsonage
You may be trying to do something similar to hutilscpp::which_first(x < 5)
which does most of its work at the R level. That is notice an expression is
of the form lhs operator rhs then evaluate each element of lhs separately




On Fri, 27 Sep 2019 at 8:35 pm, Morgan Morgan 
wrote:

> Hi,
>
> I am wondering if the below is possible?
> Let's assume I have the following expression:
>
> 1:10 < 5
>
> Is there a way at the R C API level to only evaluate the 5th element (i.e 5
> < 5) instead of evaluating the whole expression and then select the 5th
> element in the logical vector?
>
> Thank you
> Best regards
> Morgan
>
> [[alternative HTML version deleted]]
>
> __
> 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


Re: [Rd] Evaluate part of an expression at C level

2019-09-27 Thread Gábor Csárdi
Yes, you can manipulate the language object, and replace the the 1:10
with its own 5. element, and then call eval on the modified
expression. This can be simple if you know the structure of the
expression well, and difficult otherwise.

It goes like this:

SEXP lang_test(SEXP expr, SEXP idx, SEXP idxcall, SEXP env) {
  SEXP idxcall2 = PROTECT(duplicate(idxcall));
  SEXP expr2 = PROTECT(duplicate(expr));
  SETCADR(idxcall2, CADR(expr));
  SETCADDR(idxcall2, idx);
  SEXP elem = PROTECT(Rf_eval(idxcall2, env));
  SETCADR(expr2, elem);
  SEXP result = PROTECT(Rf_eval(expr2, env));
  UNPROTECT(4);
  return result;
}

You need to add some type and index checking, to make sure that expr
is a language object and has the proper length, etc.

You can call it like this:

langtest <- function(expr, idx) {
  .Call(c_lang_test, expr, idx, as.call(list(`[`, 1:10, 1)), environment())
}

We pass an indexing call to do the indexing, for simplicity, this also
supports S3 dispatch, etc.

Gabor

On Fri, Sep 27, 2019 at 11:35 AM Morgan Morgan
 wrote:
>
> Hi,
>
> I am wondering if the below is possible?
> Let's assume I have the following expression:
>
> 1:10 < 5
>
> Is there a way at the R C API level to only evaluate the 5th element (i.e 5
> < 5) instead of evaluating the whole expression and then select the 5th
> element in the logical vector?
>
> Thank you
> Best regards
> Morgan
>
> [[alternative HTML version deleted]]
>
> __
> 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] passing extra arguments to devtools::build

2019-09-27 Thread Michael Friendly
This question was posed on SO : 
https://stackoverflow.com/questions/58118495/passing-extra-argumenets-to-devtoolsbuild
 
but there has been no useful reply.

Something seems to have changed in the |devtools|package, so that the 
following commands, that used to run now give an error I can't decipher:

|>Sys.setenv(R_GSCMD="C:/Program 
Files/gs/gs9.21/bin/gswin64c.exe")>devtools::build(args 
=c('--resave-data','--compact-vignettes="gs+qpdf"'))The 
filename,directory name,or volume label syntax is incorrect. Error 
in(function(command =NULL,args =character(),error_on_status 
=TRUE,:System command error|

I've tried other alternatives with other |devtools| commands, like just 
passing a single argument, but still get the same error

|args ='--compact-vignettes="gs+qpdf"'devtools::check_win_devel(args=args)|

I'm using devtools 2.2.0, under R 3.5.2

-- 
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, ASA Statistical Graphics Section
York University  Voice: 416 736-2100 x66249
4700 Keele StreetWeb: http://www.datavis.ca | @datavisFriendly
Toronto, ONT  M3J 1P3 CANADA


[[alternative HTML version deleted]]

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


Re: [Rd] passing extra arguments to devtools::build

2019-09-27 Thread Jan Gorecki
Dear Michael,

I think R-devel mailing list is not a proper place to report issues
with devtools. I would try filling an issue in their github
repository.
If you are able to reproduce this issue using plain R without any
extra packages, then please provide such example here.

Regards,
Jan Gorecki

On Fri, Sep 27, 2019 at 3:18 PM Michael Friendly  wrote:
>
> This question was posed on SO :
> https://stackoverflow.com/questions/58118495/passing-extra-argumenets-to-devtoolsbuild
> but there has been no useful reply.
>
> Something seems to have changed in the |devtools|package, so that the
> following commands, that used to run now give an error I can't decipher:
>
> |>Sys.setenv(R_GSCMD="C:/Program
> Files/gs/gs9.21/bin/gswin64c.exe")>devtools::build(args
> =c('--resave-data','--compact-vignettes="gs+qpdf"'))The
> filename,directory name,or volume label syntax is incorrect. Error
> in(function(command =NULL,args =character(),error_on_status
> =TRUE,:System command error|
>
> I've tried other alternatives with other |devtools| commands, like just
> passing a single argument, but still get the same error
>
> |args ='--compact-vignettes="gs+qpdf"'devtools::check_win_devel(args=args)|
>
> I'm using devtools 2.2.0, under R 3.5.2
>
> --
> Michael Friendly Email: friendly AT yorku DOT ca
> Professor, Psychology Dept. & Chair, ASA Statistical Graphics Section
> York University  Voice: 416 736-2100 x66249
> 4700 Keele StreetWeb: http://www.datavis.ca | @datavisFriendly
> Toronto, ONT  M3J 1P3 CANADA
>
>
> [[alternative HTML version deleted]]
>
> __
> 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] missing imports not detected by 'R CMD check' (?)

2019-09-27 Thread Martin Maechler
> Henrik Bengtsson 
> on Tue, 24 Sep 2019 11:42:13 -0700 writes

[to me (as maintainer of 'Matrix') and allowed me to answer in public] :

> I ran into a problem where 'R CMD check' on my in-house package, which
> only indirectly depends on 'Matrix', produce errors like:
> 
> [where=, where2= namespace:Matrix>]
> Error in setGeneric("expand", function(x, ...) standardGeneric("expand")) :
>   could not find function "setGeneric"


> Looking at your https://cran.r-project.org/web/packages/Matrix/NAMESPACE:

> ## try to import all we need, but not more
> importFrom("methods"
>   ## still needed {group generics needed to be explicitly imported} ?
>  , Ops, Arith, Compare, Logic, Math, Math2, Summary, Complex
>   ## generics for which we export new methods:
>  , cbind2, rbind2, coerce, show
>  , kronecker
>   ## things we call,.. necessary when Matrix is loaded, but not attached, as 
> in

>   ## Rscript --vanilla -e 'require(methods);(M <- Matrix::Matrix(0:1,3,3));  
> as(M,"sparseMatrix")'
>  , as, is, extends, new
>  , callGeneric, callNextMethod
>  , .selectSuperClasses, .slotNames, canCoerce, packageSlot
>  , getClass, getClassDef, validObject
>  , setClass, setClassUnion, setMethod, setOldClass
>  , setValidity, slot, "slot<-", slotNames, .hasSlot
>  , signature, representation, prototype)


> I see that you do not list 'setGeneric' in importFrom("methods", ...).
> If I add that manually and reinstall 'Matrix', then 'R CMD check' no
> longer produces the above error.


> PS. My problem only reveals itself on an R installation that I built
> without installing 'recommended' packages in the system library - they
> do exist in R_LIBS_USER though.  I don't know if that's related or
> not, but just wanted to mention it.
> 
> PPS. I see similar issues with packages that uses globalVariables()
> without importFrom("utils", "globalVariables").  Hence my R-pkg-devel
> on 'Why doesn't R CMD check warn that globalVariables() is
> undefined/not imported?' post on 2019-09-24
> (https://stat.ethz.ch/pipermail/r-package-devel/2019q3/004440.html).

Thank you,  Henrik,
this is somewhat interesting and more widely relevant than just
to Matrix I think, and therefore is going to the R-devel list.

Your scenario (in PS) is a bit unusual,  but of course, you can
easily make it realistic scenario with a non-Recommended package
that is similar to Matrix  (but for "Minimal reproducible
example" !) could be much smaller.

I checked a bit further .. not systematically and found at least
two more methods /  functions I use and  the R CMD check tools
have never warned me about (and so they are not in Matrix/NAMESPACE 
   because Matrix may be older than namespaces, and even if not,
   originally, one did not import the the things from "Depends:" packages,
   where 'methods' had been for a long time in Matrix/DESCRIPTION ) :

Both 

 standardGeneric()  and 
 implicitGeneric()

are also not in Matrix' NAMESPACE and are used in Matrix/R/*.R
code, and that does not give any warnings from R CMD check.

Unfortunately, I don't have time at the moment to delve into
this to debug .. but I rather "post it" for now, so it is less
easily forgotten.

Martin

--
Martin Maechler
ETH Zurich and R Core

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