Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As it currently stands, you cannot <code>dput</code> this object. The code of <code>dput</code> contains the following loop:</p> <pre><code>if (isS4(x)) { cat("new(\"", class(x), "\"\n", file = file, sep = "") for (n in slotNames(x)) { cat(" ,", n, "= ", file = file) dput(slot(x, n), file = file, control = control) } cat(")\n", file = file) invisible() } </code></pre> <p>This handles S4 objects recursively, but it relies on the assumption an S3 object will not contain an S4 object, which in your example does not hold:</p> <pre><code>&gt; isS4(slot(poly.d,'polygons')) [1] FALSE &gt; isS4(slot(poly.d,'polygons')[[1]]) [1] TRUE </code></pre> <p><strong>Edit:</strong> Here is a work-around the limitations of <code>dput</code>. It works for the example you provided, but I don't think that it will work in general (e.g. it does not handle attributes).</p> <pre><code>dput2 &lt;- function (x, file = "", control = c("keepNA", "keepInteger", "showAttributes")){ if (is.character(file)) if (nzchar(file)) { file &lt;- file(file, "wt") on.exit(close(file)) } else file &lt;- stdout() opts &lt;- .deparseOpts(control) if (isS4(x)) { cat("new(\"", class(x), "\"\n", file = file, sep = "") for (n in slotNames(x)) { cat(" ,", n, "= ", file = file) dput2(slot(x, n), file = file, control = control) } cat(")\n", file = file) invisible() } else if(length(grep('@',capture.output(str(x)))) &gt; 0){ if(is.list(x)){ cat("list(\n", file = file, sep = "") for (i in 1:length(x)) { if(!is.null(names(x))){ n &lt;- names(x)[i] if(n != ''){ cat(" ,", n, "= ", file = file) } } dput2(x[[i]], file = file, control = control) } cat(")\n", file = file) invisible() } else { stop('S4 objects are only handled if they are contained within an S4 object or a list object') } } else .Internal(dput(x, file, opts)) } </code></pre> <p>And here it is in action:</p> <pre><code>&gt; dput2(poly.d,file=(tempFile &lt;- tempfile())) &gt; poly.d2 &lt;- dget(tempFile) &gt; all.equal(poly.d,poly.d2) [1] TRUE </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload