Re: [Rd] Should slot<-() alter its first argument?

2019-09-21 Thread Michael Lawrence via R-devel
The core of Bioconductor and the methods package itself once took
advantage of this "feature" to avoid unnecessary duplication. Since
the introduction of shallow copying, those abuses have been removed.

Note that these assignment functions always have issues due to
optimizations that assume <-() is called. For example,

>  setClass("Z", rep=representation(x="character"))
> z <- new("Z", x="orig")

> z2 <- `@<-`(z, "x", value="newer")
> .Internal(inspect(z2)) # NAMED==1, as it should be
@565446e0bdf8 25 S4SXP g0c0 [OBJ,NAM(1),S4,gp=0x10,ATT]

> `@<-`(z2, "x", value="newest")
An object of class "Z"
Slot "x":
[1] "newest"
> z2 # modified in place due to NAMED==1, because we assume assignment back to 
> itself
An object of class "Z"
Slot "x":
[1] "newest"

Since we assume <-() bumps NAMED, z2 has its NAMED cleared even though
it's obviously named:
> z2 <- `@<-`(z, "x", value="newer")
> .Internal(inspect(z2))
@56544726ae60 25 S4SXP g0c0 [OBJ,NAM(1),S4,gp=0x10,ATT]
> .Internal(inspect(`@<-`(z2, "x", value="newest"))) # NAMED == 0, same address 
> as above
@56544726ae60 25 S4SXP g0c0 [OBJ,S4,gp=0x10,ATT]

So I guess we could make slot<-() a bit safer but unless we give up
the optimizations or maybe inform the "gets" functions that they are
being called outside of complex assignment, there will be exploits.

Michael

On Thu, Sep 19, 2019 at 11:19 AM William Dunlap via R-devel
 wrote:
>
> We noticed that the slot<- function alters its first argument, which goes
> against the grain of a functional language.  The similar @<- does not
> change its first argument.  Is this intended?  The timeSeries and distr
> package depend on this altering.
>
> > setClass("Z", rep=representation(x="character"))
> > z <- new("Z", x="orig")
> > `@<-`(z, "x", value="newer")
> An object of class "Z"
> Slot "x":
> [1] "newer"
>
> > z
> An object of class "Z"
> Slot "x":
> [1] "orig"
>
> >
> > `slot<-`(z, "x", value="newest")
> An object of class "Z"
> Slot "x":
> [1] "newest"
>
> > z
> An object of class "Z"
> Slot "x":
> [1] "newest"
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> [[alternative HTML version deleted]]
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
Michael Lawrence
Scientist, Bioinformatics and Computational Biology
Genentech, A Member of the Roche Group
Office +1 (650) 225-7760
micha...@gene.com

Join Genentech on LinkedIn | Twitter | Facebook | Instagram | YouTube

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


Re: [Rd] Error: package or namespace load failed for ‘utils

2019-09-21 Thread Laurent Gautier
Thanks to all that looked at it and tried to answer.

I am reporting here what I found in the end, in the hope it helps someone
with a similar issue solve it quicker than I solved the one I had:

Having

int R_NaInt;

rather than

extern int R_NaInt;

in the header / C definitions of the cffi interface (part of the header
definitions have to be copied/prepared to be digestable by the C parser
used Python's cffi interface) was enough to send R into a confused state at
initialization (but without an obvious error message).


Le lun. 16 sept. 2019 à 03:55, Martin Maechler 
a écrit :

> > Laurent Gautier
> > on Sun, 15 Sep 2019 15:01:09 -0400 writes:
>
> > In case a search engine leads someone with the same issue
> > here, I am documenting the point I reached:
>
> > I can reproduce the issue with a small example when
> > forcing R to not load any package at startup time (using
> > an Renviron file): ``` package <- "utils" lib.loc <-
> > "" ns <-
> > loadNamespace(package, lib.loc) ```
>
> > The code path goes through
> > `registerS3methods(nsInfo$S3methods, package, env)` and
> > there to:
>
> > ``` if (methods::is(genfun, "genericFunction")) ```
>
> > The evaluation of `methods::is` reaches the line
> > triggering the error as `.identC(class1, class2)` and
> > `.identC(class2, "ANY")` both return `NA` and `NA || NA`
> > is not defined:
>
> > ```
> >> if (NA || NA) { cat("here\n") }
> > Error in if (NA || NA) { : missing value where TRUE/FALSE
> > needed ```
>
> > As I understand it `.identC()` should never return `NA`,
>
> that understanding is correct, it should return TRUE or FALSE,
> nothing else.
>
> > and if the case this would mean that R itself is an
> > unstable state (something at the C level that should not
> > have happened has happened) but this was not caught
> > earlier.
>
> yes.. something like that...
> My current diagnosis would be that something in your embedding of R
> happened
> in a way that "broke R entirely" ...
> but note that I know almost nothing about embedding R.
>
> Martin
>

[[alternative HTML version deleted]]

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


Re: [Rd] Cryptic error message from namespaceExport

2019-09-21 Thread Michael Lawrence via R-devel
Thanks. The error message will now say:

undefined exports: class inla

Will check-in after running more tests.


On Fri, Sep 6, 2019 at 10:19 AM Thierry Onkelinx 
wrote:

> Dear Michael,
>
> my package has setOldClass("inla") and the NAMESPACE
> contains exportClasses(inla) and importFrom(INLA, inla.posterior.sample)
>
> the old version of INLA uses the S3 class "inla" but does not export it.
> the new version of INLA has setOldClass("inla") and the NAMESPACE
> contains exportClasses(inla)
>
> installing my package in combination with an older INLA version works
>
> install.packages("
> https://inla.r-inla-download.org/R/stable/src/contrib/INLA_18.07.12.tar.gz";,
> repos = NULL)
> remotes::install_github("inbo/inlatools", upgrade = FALSE, force = TRUE)
>
> installing my package with a recent INLA versions yields the error
>
> install.packages("
> https://inla.r-inla-download.org/R/stable/src/contrib/INLA_19.09.03.tar.gz";,
> repos = NULL)
> remotes::install_github("inbo/inlatools", upgrade = FALSE, force = TRUE)
>
> Warning: INLA is a very large package. The old version is 87 MB, the new
> one 250 MB
>
> Best regards,
>
> ir. Thierry Onkelinx
> Statisticus / Statistician
>
> Vlaamse Overheid / Government of Flanders
> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
> FOREST
> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> thierry.onkel...@inbo.be
> Havenlaan 88 bus 73, 1000 Brussel
> www.inbo.be
>
>
> ///
> To call in the statistician after the experiment is done may be no more
> than asking him to perform a post-mortem examination: he may be able to say
> what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
>
> ///
>
> 
>
>
> Op vr 6 sep. 2019 om 17:16 schreef Michael Lawrence <
> lawrence.mich...@gene.com>:
>
>> Just to clarify, your package is exporting a class that is not
>> defined? Or is it exporting a class that is defined by a dependency
>> and then masked by setOldClass()? A simple reproducible example would
>> help.
>>
>> On Fri, Sep 6, 2019 at 7:48 AM Thierry Onkelinx via R-devel
>>  wrote:
>> >
>> > Dear all,
>> >
>> > Today I got this error message (R 3.6.1) when installing my package:
>> >
>> > Error: package or namespace load failed for ‘inlatools’ in
>> > namespaceExport(ns, exports):
>> >  undefined exports: .__C__inla
>> >
>> > My package was using setOldClass("inla") and exported the "inla" class
>> via
>> > the NAMESPACE. It imports functions from the INLA package. Older
>> versions
>> > of the INLA package did not export the "inla" class. Hence the use of
>> > setOldClass().
>> > The current version of the INLA package does export the "inla" class
>> > through it NAMESPACE. This triggered the error described above.
>> >
>> > Is the possible to improve this error message? The current message is
>> > misleading as neither packages contain the string ".__C__inla"
>> >
>> > Best regards,
>> >
>> > ir. Thierry Onkelinx
>> > Statisticus / Statistician
>> >
>> > Vlaamse Overheid / Government of Flanders
>> > INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
>> AND
>> > FOREST
>> > Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
>> > thierry.onkel...@inbo.be
>> > Havenlaan 88 bus 73, 1000 Brussel
>> > www.inbo.be
>> >
>> >
>> ///
>> > To call in the statistician after the experiment is done may be no more
>> > than asking him to perform a post-mortem examination: he may be able to
>> say
>> > what the experiment died of. ~ Sir Ronald Aylmer Fisher
>> > The plural of anecdote is not data. ~ Roger Brinner
>> > The combination of some data and an aching desire for an answer does not
>> > ensure that a reasonable answer can be extracted from a given body of
>> data.
>> > ~ John Tukey
>> >
>> ///
>> >
>> > 
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-devel@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>>
>> --
>> Michael Lawrence
>> Scientist, Bioinformatics and Computational Biology
>> Genentech, A Member of the Roche Group
>> Office +1 (650) 225-7760
>> micha...@gene.com
>>
>> Join Genentech on LinkedIn | Twitter | Facebook | Instagram | YouTube
>>
>

-- 
Michael Lawrence
Scientist, Bioinformatics and Computational Biology
Genentech, A Member of the Roche Group
Office +1 (650) 225-776