grid.arrange Not Found When gridExtra Imported into Package

4,556 views
Skip to first unread message

Dario Strbenac

unread,
Jul 25, 2014, 2:00:16 AM7/25/14
to ggp...@googlegroups.com
I made a minimal R package, and made a function that simply creates two plots and uses grid.arrange to lay them out. Even though I import gridExtra and ggplot2, I get an error :

could not find function "ggplotGrob".

I have ggplot2 1.0.0, gridExtra 0.9.1, and R 3.1.1.

The contents of NAMESPACE are :

exportPattern("^[[:alpha:]]+")
import(ggplot2, gridExtra)


Can these R packages be made to work in harmony ?

Oskar Hansson

unread,
Jan 5, 2015, 2:15:35 PM1/5/15
to ggp...@googlegroups.com

I have gridExtra under Imports in the DESCRIPTION file and have an entry import(gridExtra) in NAMESPACE. Then I use :: when calling a function e.g. gridExtra::arrangeGrob.

Also I got help from these questions to get ggsave to work in my package:

Dario Strbenac

unread,
Jan 21, 2015, 2:00:08 AM1/21/15
to ggp...@googlegroups.com
Your method doesn't work if ggplot2 is also imported, rather than depended on. The real problem was that grid.arrange called ggplotGrob directly, even though there was no guarantee that the library was loaded, because it was missing requireNamespace(ggplot2) in the code for grid.arrange also also didn't use ggplot2:: in front of the function call. This issue was fixed in the project's GitHub repository, but is still present on CRAN.

Oskar Hansson

unread,
Jan 21, 2015, 2:25:34 AM1/21/15
to ggp...@googlegroups.com
Thanks for the information. You are right that it didn't work. Perhaps I did not refresh the R session before I tested. I ended up putting gridExtra under Depends instead of Imports. That seem to work (in package strvalidator)... Sorry I forgot to update the post.
Reply all
Reply to author
Forward
0 new messages