export icon indicating copy to clipboard operation
export copied to clipboard

doc_parse_raw

Open guokai8 opened this issue 5 years ago • 19 comments

Hi, When I use graph2ppt on ubuntu system platform. It report the error:

Error in doc_parse_raw(x, encoding = encoding, base_url = base_url, as_html = as_html,  : 
  StartTag: invalid element name [68]

And below is the details: R version 3.4.4 (2018-03-15) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 16.04.5 LTS

Matrix products: default BLAS: /usr/lib/libblas/libblas.so.3.6.0 LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] export_0.2.2.9000

guokai8 avatar Nov 09 '18 19:11 guokai8

Could you please provide a full reproducible example, so we can try on our end?

tomwenseleers avatar Nov 09 '18 19:11 tomwenseleers

I just use very simple example:

library(export)
p<-plot(1:10)
graph2ppt(x=p,file="test.pptx")

I run this on ubuntu.

guokai8 avatar Nov 09 '18 19:11 guokai8

Is the problem here not just that you are trying to pass a base R plot as an object, which is not possible? (You can only do that with ggplots) So you would have to do instead

library(export)
plot(1:10)
graph2ppt(file="test.pptx")

Does that work OK for you?

tomwenseleers avatar Nov 09 '18 20:11 tomwenseleers

I am sorry I don't have graphic interface on my server.

guokai8 avatar Nov 09 '18 20:11 guokai8

Ha then you would have to use

library(export)
plot.fun = function(){
  print(plot(1:10))
}
graph2ppt(fun=plot.fun, file="test.pptx")

I think... (You have to set your working directory first, or include the path in the filename)

tomwenseleers avatar Nov 09 '18 20:11 tomwenseleers

I try it but it doesn't work. Thanks!

guokai8 avatar Nov 09 '18 21:11 guokai8

And does exporting ggplots work for you? E.g.

library(export)
library(ggplot2)
library(datasets)
x=qplot(Sepal.Length, Petal.Length, data = iris, 
        color = Species, size = Petal.Width, alpha = I(0.7))
graph2ppt(x=x, file="test.pptx")


tomwenseleers avatar Nov 10 '18 07:11 tomwenseleers

One other thing that may be causing problems is that I believe export is expecting the latest version of R, R 3.5.1... When I try on my ubuntu workstation here it all works so I am not quite sure where the problem is coming from... Could be that it has to do something with the fact you don't have a graphics interface on your server (we've always tested the package from within RStudio with a graphics device open).... But I'll look into it...

tomwenseleers avatar Nov 10 '18 07:11 tomwenseleers

Could you try if this works on your configuration

library(officer)
doc <- read_pptx()
doc <- add_slide(doc, "Title and Content", "Office Theme")
doc <- ph_with_vg_at(doc, code = barplot(1:5, col = 2:6),
  left = 1, top = 2, width = 6, height = 4)
print(doc, target = "vg.pptx")

If that one doesn't work without a graphics interface then I'm afraid export also won't work, since we rely on officer and rvg...

tomwenseleers avatar Nov 13 '18 11:11 tomwenseleers

Hi, I try it. it works. Thanks!

guokai8 avatar Nov 13 '18 13:11 guokai8

So officer works, but the export package still doesn't work? Or does exporting ggplots work also in export?

tomwenseleers avatar Nov 13 '18 13:11 tomwenseleers

Yes. export seems doesn't work but officer did. I haven't try ggplots.

guokai8 avatar Nov 13 '18 13:11 guokai8

OK I'll look into it then, because that means I should be able to fix export to make it work for this configuration... Would you know by any chance how to set up an R installation without a screen device?

tomwenseleers avatar Nov 13 '18 13:11 tomwenseleers

It automatic setup on the server. Btw, the thing happened since I want build an shiny app("http://hurlab.med.und.edu/VennDetail/") by using your export package to export ppt and doc. Now it works. I found the reason also comes from UpSetR when I try to save the upset figure which always call grid.newpage function. I modified the upset code and used the ph_with_vg_at function.

guokai8 avatar Nov 13 '18 14:11 guokai8

We just did an update to the github export version to make it work also for R users without a screen device. You can install it with devtools::install_github("tomwenseleers/export") See if that works for you!

tomwenseleers avatar Nov 14 '18 15:11 tomwenseleers

OK. I will try the new version. Thanks!

guokai8 avatar Nov 14 '18 15:11 guokai8

And did it work for you in the end?

tomwenseleers avatar Nov 19 '18 08:11 tomwenseleers

Hi Tom,

I am having this same issue. graph2ppt works in Rstudio when I export a dendrogram (or anything):

Example:

plot(hc.dend)
graph2ppt(file="dendrograms.pptx", append=F)

But returns the error below when I run it as an Rscript from the bash command line (no screen device):

Error in doc_parse_raw(x, encoding = encoding, base_url = base_url, as_html = as_html,  :
  StartTag: invalid element name [68]
Calls: graph2ppt ... as_xml_document.character -> read_xml.raw -> doc_parse_raw

I re-installed the package using devtools::install_github("tomwenseleers/export") & that didn't fix it.

Thanks

jchap14 avatar Dec 05 '18 14:12 jchap14

Hi, Sorry for the late reply. it seems the new version still not works. Kai

guokai8 avatar Dec 05 '18 14:12 guokai8