plotTangentSpace: Running into odd glitch when trying to export results to Excel

582 views
Skip to first unread message

Derek Woller

unread,
Jul 12, 2017, 11:17:05 PM7/12/17
to geomorph R package

Hello, all! I have been exploring geomorph for about a week and, so far, it does everything I want it to do, but I just ran across an odd road block that's stumping me. I run a PCA and wish to export the following three sets of resulting values to Excel:

1) pc.summary

2) pc.scores

3) pc.shapes

And I do this using the following command:

> write.xlsx(cercuspca$pc.summary, "c:/Users/asili/Documents/Cercus/TEST.xlsx")

Now, it works fine for #2 and 3, but when I try #1, I always get this specific error message:

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
  cannot coerce class ""summary.prcomp"" to a data.frame

So, I finally decided to try converting the data into a geomorph data frame and then try to export it to Excel that way, so I used the command:
  
  > testgdf <- geomorph.data.frame(shape=cercuspca$pc.summary)

And, again, it worked great with #2 and 3, but for #1, I get this:

Error in geomorph.data.frame(shape = cercuspca$pc.summary) : 
  Some input is either dimensionless or inappropriate for data frames

What's happening here? I'm able to call:

cercuspca$pc.summary

just fine and see the results within the console, so I could simply copy and paste the results into Excel, but I'f prefer that all my code works in harmony because I'll be running the full script with several shapes. I'm hoping I'm just overlooking something simple here...

Not sure it helps, but I'm using RStudio Version 1.0.143 on a PC running Win10.

Mike Collyer

unread,
Jul 12, 2017, 11:59:20 PM7/12/17
to Derek Woller, geomorph R package
Derek, 

The only glitch is that the function you are trying to use writes data frames to excel files but not all of the objects are data frames. The error statement reveals this, as the function tries to coerce objects into data frames. 

It's a limitation of the write.xlsx function rather an inherent problem with the other functions. Not every bit of output can be a data frame. 

Cheers
Mike

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.
To view this discussion on the web, visit https://groups.google.com/d/msgid/geomorph-r-package/1626a750-f780-48f3-8919-8c13d0f9d7cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Derek Woller

unread,
Jul 13, 2017, 12:10:47 AM7/13/17
to geomorph R package, asi...@gmail.com
Mike, I had a sneaking suspicion that might be the case based on how I was reading the error codes, but I was holding out hope since I've been able to export many sets of results from geomorph functions so far. Seems odd to me that this particular result is unable to have the same exportation done to it - any idea why this particular one is finicky? I presume it's simply formatted incorrectly for easy export on the back end? 

Is there another way to get this particular set of data out of RStudio that doesn't require basic copy and pasting?

Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.

Mike Collyer

unread,
Jul 13, 2017, 6:45:35 AM7/13/17
to Derek Woller, geomorph R package
Derek,

The pc.summary is a list of multiple objects, the same as one would find with prcomp.  The only way to make it data frame coercible is to isolate part of that list that is also data frame coercible.  For example:

myPCA$pc.summary <- myPCA$pc.summary$importance # this is the table of percent explained for eigenvectors
write.xlsx(myPCA$pc.summary, “filename and path”)

Or you can simply write some of the subcomponents

write.xlsx(myPCA$pc.summary$importance, “filename and path”)
write.xlsx(myPCA$pc.summary$rotation, “another filename and path”)
write.xlsx(myPCA$pc.summary$x, “yet another filename and path”)

And if you are interested in just what you can pull out,

attributes(myPCA$pc.summary)

will list all objects.

Cheers!
Mike

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.
Reply all
Reply to author
Forward
0 new messages