"Export" package in R - do analogues exist?
1
0
Entering edit mode
4.7 years ago
tanya_fiskur ▴ 70

Hi everyone!

I had one favorite function, extremely useful for adjusting plots: graph2ppt. It allowed to change the text parts of the plot (labels, legend, everything) directly in the power point.

It was inside the "export" package, which is removed from CRAN repository (https://cran.r-project.org/web/packages/export/index.html). I tried to install the version from the archive, but there are some issues and the package doesn't work.

Do you know any analogues of that function?

Thank you in advance!

R • 6.2k views
ADD COMMENT
1
Entering edit mode
4.7 years ago

You should be able to get it working by downloading the gzipped 'tarball' from HERE, and then installing manually. You may, first, have to install other dependencies, though. Here is what I had to do:

install.packages('export_0.2.2.tar.gz')
ERROR: dependencies ‘officer’, ‘rvg’, ‘flextable’, ‘rgl’, ‘stargazer’ are not available for package ‘export’

Okay, so...

install.packages('officer')
install.packages('rvg')
install.packages('flextable')
install.packages('rgl')
install.packages('stargazer')

install.packages('export_0.2.2.tar.gz')

Now load the package:

require(export)

graph2ppt
function (...) 
graph2office(type = "PPT", ...)
<bytecode: 0x5a71038>
<environment: namespace:export>

Kevin

ADD COMMENT
0
Entering edit mode

Thank you! Did you try to export a plot using the function? Did it work?

I tried to copy your example. I downloaded the package (and it lies in the "download" folder, should I place it somewhere else?) and ran the code that you used. I see the next error:

error

(the prinscreen seems not to attach properly for some reason, so I copy the error as a text: "Installing package into ‘C:/Users/Poisk/Documents/R/win-library/3.6’ (as ‘lib’ is unspecified) Warning in install.packages : package ‘export_0.2.2.tar.gz’ is not available (for R version 3.6.3)"

What do I do wrong?

ADD REPLY
0
Entering edit mode

You can place the archive / file anywhere on your disk. As you are on Windows, please install it like this (assuming that the file is saved under 'C:/Users/Poisk/download/'):

install.packages('C:/Users/Poisk/download/export_0.2.2.tar.gz', repos = NULL, type = 'source')

All other packages installed in the correct way - yes?

ADD REPLY
0
Entering edit mode

Yes, and the "export" package installed :) But it doesn't work anyway:

ggplot(alls_nolncRNA,aes(x=Length, fill=Source)) + geom_density(color='black',alpha=0.5) + xlim(c(0,20000)) + xlab('Transcript length, bp') + ylab('Density'))

graph2ppt(file="Rplot.pptx",width=7,height=6)

Error: 'ph_with_vg_at' is defunct. Use 'officer::ph_with' instead. See help("Defunct")

Does it export a plot in your case?

ADD REPLY
0
Entering edit mode

You can probably just edit the function, to be honest. Here it is (just type graph2office at your command prompt):

graph2office  <- function (x = NULL, file = "Rplot", fun = NULL, type = c("PPT", 
    "DOC"), append = FALSE, aspectr = NULL, width = NULL, height = NULL, 
    scaling = 100, paper = "auto", orient = ifelse(type[1] == 
        "PPT", "landscape", "auto"), margins = c(top = 0.5, right = 0.5, 
        bottom = 0.5, left = 0.5), center = TRUE, offx = 1, offy = 1, 
    upscale = FALSE, vector.graphic = TRUE, ...) 
{
    margins = rep_len(margins, 4)
    names(margins) = c("top", "right", "bottom", "left")
    type = toupper(type)
    type = match.arg(type, c("PPT", "DOC"))
    if (type == "PPT" | type == "PPTX") {
        ext = ".pptx"
        type = "PPT"
    }
    if (type == "DOC" | type == "DOCX") {
        ext = ".docx"
        type = "DOC"
    }
    file = sub("^(.*)[.].*", "\\1", file)
    file = paste0(file, ext)
    obj = x
    if (is.null(obj) & is.null(fun)) {
        p = captureplot()
    }
    else {
        p = obj
    }
    if (inherits(p, "list")) {
        stop("base R plots cannot be passed as objects, use ggplot2 or lattice plots instead")
    }
    myplot = if (is.null(fun)) {
        function(pl = p) print(pl)
    }
    else {
        fun
    }
...
...
    print(doc, target = file)
    message(paste0("Exported graph as ", file))
}

You could start by changing instances of ph_with_vg_at to officer::ph_with. There may be subsequent errors, but I am not to know that yet.

ADD REPLY
0
Entering edit mode

Ohh, it indeed is something inside. There is nothing about ph_with_vg_at or officer::ph_with in the graph2office function. It seems to be something inside rgv package, or officer (here is the picture: https://ibb.co/TcXxbnN )

Thank you very much for your help!

Could you probably test whether the exporting function works in your case? Just to understand whether it's a problem of my computer, or it exists for everyone who has R 3.6.3. (if you have R 3.6.3, of course)

ADD REPLY
1
Entering edit mode

Ah, yes! - I have the same error. I also use R 3.6.3. I have tried to get around it but it seems like it could take a lot of time. I searched, though, and there are quite a few other possibilities online:

It seems that export merely provided wrapper functions that utilised these other packages.

ADD REPLY
1
Entering edit mode

Thank you! That's exactly what I was looking for. And thank you for your help in general.

ADD REPLY
1
Entering edit mode

Btw :). I tried all them, they are not supported by the last R version too. Ok, I will modify plot in the R itself and hope that the developers will fix it one day. Just for information

ADD REPLY

Login before adding your answer.

Traffic: 1931 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6