Comments (2)
This is closely related to issue #42, which involved this code:
a <- structure ( c , b = c )
attributes ( a )
so I'll address them both here.
from pqr.
There are two issues here. One is what sort of object these "structure" calls create. The other is what happens when you try to print them.
Regarding the first issue, note that "structure" isn't a primitive, so I'll look at the equivalent with "attrib" just to avoid any confusion from the details of "structure" (but I think there's no real difference). It seems that the same sort of object gets created by pqR-2020-07-23 and R-4.0.2. One thing to note is that primitive functions in both pqR-2020-07-23 and R-4.0.2 cannot be copied, so the attribute gets put on all instances of them (which are really the same instance).
Here's an example an with ordinary object (same happens with an ordinary function created with "function"):
> a<-1; attr(a,"fred")<-a; attributes(a)
$fred
[1] 1
The 1 gets duplicated before being attached as an attribute, so the structure is not recursive.
Here's an example with a primitive function (same result in pqR-2020-07-23 and R-4.0.2):
> x <- c; attr(x,"fred") <- 1
> attributes(x)
$fred
[1] 1
> attributes(c)
$fred
[1] 1
Attaching an attribute to x attaches the attribute to c as well, because the primitive function c can't be duplicated.
When you attach c as an attribute to itself, a recursive structure is created, because it can't be copied before being attached. For example:
> attr(c,"fred") <- c
The print representation of this is infinite.
One could argue that it should be possible to duplicate primitive functions, or that attaching attributes to them should not be allowed (as it is not allowed for NULL, which also can't be duplicated). But that's not the way it is in both pqR-2020-07-23 and R-4.0.2. I'd advise against writing code that relies on this behaviour, since it seems possible that it may change (as it did for NULL not too long ago).
So the second question is what happens when you try to print one of these recursive objects with an infinite print representation.
One difference is that pqR doesn't always print the attribute, while R-4.0.2 does. So in pqR-2020-07-23 you get the following:
> attr(c,"fred") <- c
> c
function (..., recursive = FALSE) .Primitive("c")
pqR didn't attempt to print the attributes on the primitive function c, so the problem doesn't arise. But R-4.0.2 does print the attributes, and starts printing an infinite representation, until it gets a buffer overlow (but doesn't crash).
However, if you explicitly ask for the attributes, pqR will try to print them:
> attr(c,"fred") <- c
>attributes(c)
$fred
function (..., recursive = FALSE) .Primitive("c")
attr(,"fred")
function (..., recursive = FALSE) .Primitive("c")
attr(,"fred")attr(,"fred")
function (..., recursive = FALSE) .Primitive("c")
[ and so forth ]
which goes on until pqR gets buffer overflow (and crashes).
So the only remaining question is why pqR crashes rather than just printing a buffer overflow message and stopping with an error. That's a bug, which I'll try to track down. It may also arise in other contexts where for some reason a really long print representation gets created.
from pqr.
Related Issues (20)
- What is preventing the merge of pqR into R? HOT 1
- pqR side by side with GNU-R HOT 8
- T and F don't work with mat_mult_with_BLAS configuration argument
- Docker image for pqR HOT 3
- No window version available HOT 1
- Incompatible library version HOT 3
- Will pqR code be merged to R? HOT 9
- Missing <R_ext/sggc-app.h> HOT 11
- Proposal of new feature: native 64 bit integers support HOT 2
- R/time.R - filename restricted? HOT 5
- Update formula does not work as expected HOT 6
- make error: multiple definitions HOT 6
- segfault when using attributes HOT 1
- floating point exception
- pqR aborted when using plot
- Problems with installation ubuntu 20.04 HOT 5
- Pqr and running Rstudio on mac
- Installation fails on Slackware 15.0 HOT 13
- Slow pqR loops vs R (CRAN)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pqr.