Re: [R-pkg-devel] Using ggplot2 within another package

2021-04-24 Thread Ben Bolker
;>
     >>>
https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html
<https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html>
     >>>
<https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html
<https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html>>
     >>>
     >>> Cheers,
     >>>
     >>> -Robert
     >>>
     >>> On Thu, Apr 22, 2021 at 4:39 PM Paul SAVARY
     >>> mailto:paul.sav...@univ-fcomte.fr>
<mailto:paul.sav...@univ-fcomte.fr
<mailto:paul.sav...@univ-fcomte.fr>>> wrote:
     >>>
     >>> Hi Kevin,
     >>>
     >>> I was faced to the same problem and I used 'aes_string()'
instead
     >>> of 'aes()'. You can then just write the name of the columns
     >>> containing the data to plot as character strings.
     >>>
     >>> Example:
     >>>
     >>> myPlot <- function(myData, ...) {
     >>>     # get ready
     >>>     ggplot(myData, aes_string(x = "myX", y = "myY")) +
     >>>        # add my decorations
         >>>        theme_bw()
         >>> }
     >>>
     >>> It is probably already the case for your function but you
need to
     >>> include #' @import ggplot2 in your function preamble (if I
am not
     >>> wrong).
     >>>
     >>> Kind regards
     >>> Paul
     >>>
     >>> - Mail original -
     >>> De: "Kevin R. Coombes" mailto:kevin.r.coom...@gmail.com>
     >>> <mailto:kevin.r.coom...@gmail.com
<mailto:kevin.r.coom...@gmail.com>>>
     >>> À: "r-package-devel" mailto:r-package-devel@r-project.org>
     >>> <mailto:r-package-devel@r-project.org
<mailto:r-package-devel@r-project.org>>>
     >>> Envoyé: Jeudi 22 Avril 2021 22:28:55
     >>> Objet: [R-pkg-devel] Using ggplot2 within another package
     >>>
     >>> Hi,
     >>>
     >>> I'm trying to help clean up an R package for someone else to
     >>> submit to
     >>> CRAN. He has used ggplot2 to implement a plotting function
for the
     >>> kinds
     >>> of things that his packages generates. His plotting routine
basically
     >>> looks like (after changing names to protect the innocent):
     >>>
     >>> myPlot <- fucntion(myData, ...) {
     >>>     # get ready
     >>>     ggplot(myData, aes(x = myX, y = myY)) +
     >>>    # add my decorations
     >>>    theme_bw()
     >>> }
     >>>
     >>> Of course, "R CMD check --as-cran" complains that there is
no global
     >>> binding for "myX" or "myY" since they are columns defined
in the
     >>> data.frame "myData".
     >>>
     >>> What is the best way to work around this issue?
     >>>
     >>> Of course, dinosaurs like myself might be tempted to
suggest just
     >>> using
     >>> plain old "plot", so I don't need to see those suggestions.
     >>>
     >>> Do I just ignore the usual ggplot conventions and write
"myData$myX"
     >>> inside "aes"  in order to appease the CRAN checker? Or is
there some
     >>> tidy-er way to solve this problem?
     >>>
     >>> Thanks,
     >>>    Kevin
     >>>
     >>> __
     >>> R-package-devel@r-project.org
<mailto:R-package-devel@r-project.org>
     >>> <mailto:R-package-devel@r-project.org
<mailto:R-package-devel@r-project.org>> mailing list
     >>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
<https://stat.ethz.ch/mailman/listinfo/r-package-devel>
     >>> <https://stat.ethz.ch/mailman/listinfo/r-package-devel
<https://stat.ethz.ch/mailman/listinfo/r-package-devel>>
     >>>
     >>> __
     >>> R-package-devel@r-project.org
<mailto:R-package-devel@r-project.org>
     >>> <mailto:R-package-devel@r-project.org
<mailto:R-package-devel@r-project.org>> mailing list
     >>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
<https://stat.ethz.ch/mailman/listinfo/r-package-devel>
     >>> <https://stat.ethz.ch/mailman/listinfo/r-package-devel
<https://stat.ethz.ch/mailman/listinfo/r-package-devel>>
     >>>
     >>
     >>
     >> [[alternative HTML version deleted]]
     >>
     >> __
     >> R-package-devel@r-project.org
<mailto:R-package-devel@r-project.org> mailing list
     >> https://stat.ethz.ch/mailman/listinfo/r-package-devel
<https://stat.ethz.ch/mailman/listinfo/r-package-devel>
     >>

     > __
     > R-package-devel@r-project.org
<mailto:R-package-devel@r-project.org> mailing list
     > https://stat.ethz.ch/mailman/listinfo/r-package-devel
<https://stat.ethz.ch/mailman/listinfo/r-package-devel>

__
R-package-devel@r-project.org <mailto:R-package-devel@r-project.org>
mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel
<https://stat.ethz.ch/mailman/listinfo/r-package-devel>



__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Using ggplot2 within another package

2021-04-24 Thread Bill Dunlap
t;> Hi Kevin,
> >>>
> >>> I was faced to the same problem and I used 'aes_string()' instead
>     >>> of 'aes()'. You can then just write the name of the columns
> >>> containing the data to plot as character strings.
> >>>
> >>> Example:
> >>>
> >>> myPlot <- function(myData, ...) {
> >>> # get ready
> >>> ggplot(myData, aes_string(x = "myX", y = "myY")) +
> >>># add my decorations
> >>>theme_bw()
> >>> }
> >>>
> >>> It is probably already the case for your function but you need to
> >>> include #' @import ggplot2 in your function preamble (if I am not
> >>> wrong).
> >>>
> >>> Kind regards
> >>> Paul
> >>>
> >>> - Mail original -
> >>> De: "Kevin R. Coombes"  >>> <mailto:kevin.r.coom...@gmail.com>>
> >>> À: "r-package-devel"  >>> <mailto:r-package-devel@r-project.org>>
> >>> Envoyé: Jeudi 22 Avril 2021 22:28:55
> >>> Objet: [R-pkg-devel] Using ggplot2 within another package
> >>>
> >>> Hi,
> >>>
> >>> I'm trying to help clean up an R package for someone else to
> >>> submit to
> >>> CRAN. He has used ggplot2 to implement a plotting function for the
> >>> kinds
> >>> of things that his packages generates. His plotting routine
> basically
> >>> looks like (after changing names to protect the innocent):
> >>>
> >>> myPlot <- fucntion(myData, ...) {
> >>> # get ready
> >>> ggplot(myData, aes(x = myX, y = myY)) +
> >>># add my decorations
> >>>theme_bw()
> >>> }
> >>>
> >>> Of course, "R CMD check --as-cran" complains that there is no
> global
> >>> binding for "myX" or "myY" since they are columns defined in the
> >>> data.frame "myData".
> >>>
> >>> What is the best way to work around this issue?
> >>>
> >>> Of course, dinosaurs like myself might be tempted to suggest just
> >>> using
> >>> plain old "plot", so I don't need to see those suggestions.
> >>>
> >>> Do I just ignore the usual ggplot conventions and write
> "myData$myX"
> >>> inside "aes"  in order to appease the CRAN checker? Or is there
> some
> >>> tidy-er way to solve this problem?
> >>>
> >>> Thanks,
> >>>Kevin
> >>>
> >>> __
> >>> R-package-devel@r-project.org
> >>> <mailto:R-package-devel@r-project.org> mailing list
> >>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> >>> <https://stat.ethz.ch/mailman/listinfo/r-package-devel>
> >>>
> >>> __
> >>> R-package-devel@r-project.org
> >>> <mailto:R-package-devel@r-project.org> mailing list
> >>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> >>> <https://stat.ethz.ch/mailman/listinfo/r-package-devel>
> >>>
> >>
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> __
> >> R-package-devel@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> >>
>
> > __
> > R-package-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Using ggplot2 within another package

2021-04-24 Thread Martin Maechler
>>>>> Ben Bolker 
>>>>> on Thu, 22 Apr 2021 17:27:49 -0400 writes:

> For some reason that I don't remember, an R core member once told me 
> that they prefer x <- y <- NULL to utils::globalVariables(c("x","y")) - 

That could have been me.  Even though I think I still have some
globalVariables() statements in some of my package sources, I've
decided that it *harms* really, notably for relatively common variable names 
such
as "x":   It declares them "global"
{ for the purpose of codetools::globalVariables() } everywhere,
i.e. for all functions in the package namespace and that
basically kills the reliability of  globalVariables() checking
for the whole package.


> although I have also encountered problems with that strategy in edge 
cases.

well, when?

> Here's an example from StackOverflow from today where for some reason 
> I don't understand, evaluation of function arguments interacts with 
> non-standard/lazy evaluation within a dplyr function such that 'foo' 
> works while 'x$foo' doesn't ... don't know if it's a similar case.

> 
https://stackoverflow.com/questions/67218258/getting-error-error-in-usemethodfilter-no-applicable-method-for-filter/67220198#67220198


{ ceterum censeo ... to use NSE (non-standard-evaluation) for
  user convenience and to call this (together with really good
  ideas)  "tidy" has been one of the biggest euphemisms in the history of
  statistical computing ...  but yes, that's just my personal opinon  }

> On 4/22/21 5:19 PM, Kevin R. Coombes wrote:
>> Thanks.
>> 
>> Obviously, long. long ago, (in a galaxy not far enough away), Paul's
>> suggestion of using "aes_string" was the correct one, since "aes" uses
>> non-standard evaluation. (And to quote somebody from an R fortune
>> cookie, "The problem with non-standard evaluation is that it is
>> non-standard.") But teh documentation at the end oft he link provided by
>> Robert explivityl tells you not to do that, since "aes_string is
>> deprecated".  And reading more carefully into the manual page for
>> aes_string, one does indeed find the statement that the function is
>> "soft deprecated". I'm not sure what that means, other than someone on
>> the development team doesn't like it.
>> 
>> Instead, the vignette says you should
>>    importFrom("rlang", ".data")
>> in your NAMESPACE, and write
>>    ggplot(myData, aes(x = .data$myX, y = .data$myY))
>> 
>> And now my dinosaur question: That looks like using one non-standard
>> hack to cover up the problems with another non-standard hack. Why the
>> heck  is that any better for the developer than writing
>>    ggplot(myData, aes(x = myData$myX, y = myData$myY))
>> 
>> or using Dirk Eddelbuettel's suggestion of calling 
utils::globalVariables ??
>> 
>> It's time to tell those kids to get off of my lawn.
>>   Kevin
>> 
>> On 4/22/2021 4:45 PM, Robert M. Flight wrote:
>>> Kevin,
>>> 
>>> This vignette from ggplot2 itself gives the "officially recommended"
>>> ways to avoid the warnings from R CMD check
>>> 
>>> https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html
>>> <https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html>
>>> 
>>> Cheers,
>>> 
>>> -Robert
>>> 
>>> On Thu, Apr 22, 2021 at 4:39 PM Paul SAVARY
>>> mailto:paul.sav...@univ-fcomte.fr>> wrote:
>>> 
>>> Hi Kevin,
>>> 
>>> I was faced to the same problem and I used 'aes_string()' instead
>>> of 'aes()'. You can then just write the name of the columns
>>> containing the data to plot as character strings.
>>> 
>>> Example:
>>> 
>>> myPlot <- function(myData, ...) {
>>>     # get ready
    >>>     ggplot(myData, aes_string(x = "myX", y = "myY")) +
>>>        # add my decorations
>>>        theme_bw()
>>> }
>>> 
>>> It is probably already the case for your function but you need to
>>> include #' @import ggplot2 in your function preamble (if I am not
>>> wrong).
>>> 
>>> Kind regards
>>> Paul
>>> 
>>> - Mail original -
>>> De: "Kevin R. Coombes&qu

Re: [R-pkg-devel] Using ggplot2 within another package

2021-04-23 Thread Tiago Olivoto
Hi everyone,
One suggestion would be import ggplot2 and using tidy eval operators to
create a function. One simple reproducible example would be

library(ggplot2)
my_hist <- function(df, var){
  ggplot(df, aes({{var}})) +
geom_histogram()
}

df <- data.frame(my_var = rnorm(400, 10, 2))
my_hist(df = df, var = my_var)

All the best
Tiago

Em sex., 23 de abr. de 2021 às 09:04, Mike Collyer 
escreveu:

> Hi Kevin,
>
> I recently developed a plot function in a package that used ggplot and ran
> into the same problem.  I overcame the problem with a first line of
> (useless) code as
>
> myX <- myY <- NULL
>
> I found the solution inelegant but it worked.
>
> cheers!
> Mike
>
> > On Apr 22, 2021, at 4:28 PM, Kevin R. Coombes 
> wrote:
> >
> > Hi,
> >
> > I'm trying to help clean up an R package for someone else to submit to
> CRAN. He has used ggplot2 to implement a plotting function for the kinds of
> things that his packages generates. His plotting routine basically looks
> like (after changing names to protect the innocent):
> >
> > myPlot <- fucntion(myData, ...) {
> ># get ready
> >ggplot(myData, aes(x = myX, y = myY)) +
> >   # add my decorations
> >   theme_bw()
> > }
> >
> > Of course, "R CMD check --as-cran" complains that there is no global
> binding for "myX" or "myY" since they are columns defined in the data.frame
> "myData".
> >
> > What is the best way to work around this issue?
> >
> > Of course, dinosaurs like myself might be tempted to suggest just using
> plain old "plot", so I don't need to see those suggestions.
> >
> > Do I just ignore the usual ggplot conventions and write "myData$myX"
> inside "aes"  in order to appease the CRAN checker? Or is there some
> tidy-er way to solve this problem?
> >
> > Thanks,
> >   Kevin
> >
> > __
> > R-package-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Using ggplot2 within another package

2021-04-23 Thread Mike Collyer
Hi Kevin,

I recently developed a plot function in a package that used ggplot and ran into 
the same problem.  I overcame the problem with a first line of (useless) code as

myX <- myY <- NULL

I found the solution inelegant but it worked.

cheers!
Mike

> On Apr 22, 2021, at 4:28 PM, Kevin R. Coombes  
> wrote:
> 
> Hi,
> 
> I'm trying to help clean up an R package for someone else to submit to CRAN. 
> He has used ggplot2 to implement a plotting function for the kinds of things 
> that his packages generates. His plotting routine basically looks like (after 
> changing names to protect the innocent):
> 
> myPlot <- fucntion(myData, ...) {
># get ready
>ggplot(myData, aes(x = myX, y = myY)) +
>   # add my decorations
>   theme_bw()
> }
> 
> Of course, "R CMD check --as-cran" complains that there is no global binding 
> for "myX" or "myY" since they are columns defined in the data.frame "myData".
> 
> What is the best way to work around this issue?
> 
> Of course, dinosaurs like myself might be tempted to suggest just using plain 
> old "plot", so I don't need to see those suggestions.
> 
> Do I just ignore the usual ggplot conventions and write "myData$myX" inside 
> "aes"  in order to appease the CRAN checker? Or is there some tidy-er way to 
> solve this problem?
> 
> Thanks,
>   Kevin
> 
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Using ggplot2 within another package

2021-04-22 Thread Gábor Csárdi
On Thu, Apr 22, 2021 at 11:19 PM Kevin R. Coombes
 wrote:
[...]
> Instead, the vignette says you should
> importFrom("rlang", ".data")
> in your NAMESPACE, and write
> ggplot(myData, aes(x = .data$myX, y = .data$myY))
>
> And now my dinosaur question: That looks like using one non-standard
> hack to cover up the problems with another non-standard hack. Why the
> heck  is that any better for the developer than writing
> ggplot(myData, aes(x = myData$myX, y = myData$myY))

Well, for one, because it does not always work, see e.g. the examples
and links here:
https://github.com/tidyverse/ggplot2/issues/2693

> or using Dirk Eddelbuettel's suggestion of calling utils::globalVariables ??

Because if you refer to a hundred different columns in your plots, then
you'll need to add all of them to globalVariables(), and this is error prone
and cumbersome to update. If you only refer a handful of columns, then sure,
this will work as well.

Gabor

[...]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Using ggplot2 within another package

2021-04-22 Thread Ben Bolker
  For some reason that I don't remember, an R core member once told me 
that they prefer x <- y <- NULL to utils::globalVariables(c("x","y")) - 
although I have also encountered problems with that strategy in edge cases.


 Here's an example from StackOverflow from today where for some reason 
I don't understand, evaluation of function arguments interacts with 
non-standard/lazy evaluation within a dplyr function such that 'foo' 
works while 'x$foo' doesn't ... don't know if it's a similar case.


https://stackoverflow.com/questions/67218258/getting-error-error-in-usemethodfilter-no-applicable-method-for-filter/67220198#67220198

On 4/22/21 5:19 PM, Kevin R. Coombes wrote:

Thanks.

Obviously, long. long ago, (in a galaxy not far enough away), Paul's
suggestion of using "aes_string" was the correct one, since "aes" uses
non-standard evaluation. (And to quote somebody from an R fortune
cookie, "The problem with non-standard evaluation is that it is
non-standard.") But teh documentation at the end oft he link provided by
Robert explivityl tells you not to do that, since "aes_string is
deprecated".  And reading more carefully into the manual page for
aes_string, one does indeed find the statement that the function is
"soft deprecated". I'm not sure what that means, other than someone on
the development team doesn't like it.

Instead, the vignette says you should
     importFrom("rlang", ".data")
in your NAMESPACE, and write
     ggplot(myData, aes(x = .data$myX, y = .data$myY))

And now my dinosaur question: That looks like using one non-standard
hack to cover up the problems with another non-standard hack. Why the
heck  is that any better for the developer than writing
     ggplot(myData, aes(x = myData$myX, y = myData$myY))

or using Dirk Eddelbuettel's suggestion of calling utils::globalVariables ??

It's time to tell those kids to get off of my lawn.
    Kevin

On 4/22/2021 4:45 PM, Robert M. Flight wrote:

Kevin,

This vignette from ggplot2 itself gives the "officially recommended"
ways to avoid the warnings from R CMD check

https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html
<https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html>

Cheers,

-Robert

On Thu, Apr 22, 2021 at 4:39 PM Paul SAVARY
mailto:paul.sav...@univ-fcomte.fr>> wrote:

 Hi Kevin,

 I was faced to the same problem and I used 'aes_string()' instead
 of 'aes()'. You can then just write the name of the columns
 containing the data to plot as character strings.

 Example:

 myPlot <- function(myData, ...) {
     # get ready
     ggplot(myData, aes_string(x = "myX", y = "myY")) +
        # add my decorations
        theme_bw()
 }

 It is probably already the case for your function but you need to
 include #' @import ggplot2 in your function preamble (if I am not
 wrong).

 Kind regards
 Paul

 - Mail original -
 De: "Kevin R. Coombes" mailto:kevin.r.coom...@gmail.com>>
 À: "r-package-devel" mailto:r-package-devel@r-project.org>>
 Envoyé: Jeudi 22 Avril 2021 22:28:55
 Objet: [R-pkg-devel] Using ggplot2 within another package

 Hi,

 I'm trying to help clean up an R package for someone else to
 submit to
 CRAN. He has used ggplot2 to implement a plotting function for the
 kinds
 of things that his packages generates. His plotting routine basically
 looks like (after changing names to protect the innocent):

 myPlot <- fucntion(myData, ...) {
     # get ready
     ggplot(myData, aes(x = myX, y = myY)) +
    # add my decorations
    theme_bw()
 }

 Of course, "R CMD check --as-cran" complains that there is no global
 binding for "myX" or "myY" since they are columns defined in the
 data.frame "myData".

 What is the best way to work around this issue?

 Of course, dinosaurs like myself might be tempted to suggest just
 using
 plain old "plot", so I don't need to see those suggestions.

 Do I just ignore the usual ggplot conventions and write "myData$myX"
 inside "aes"  in order to appease the CRAN checker? Or is there some
 tidy-er way to solve this problem?

 Thanks,
    Kevin

 __
 R-package-devel@r-project.org
 <mailto:R-package-devel@r-project.org> mailing list
 https://stat.ethz.ch/mailman/listinfo/r-package-devel
 <https://stat.ethz.ch/mailman/listinfo/r-package-devel>

 __
 R-package-devel@r-project.org
 <mailto:R-package-devel@r-project.org> mailing list
 https://stat.ethz.ch/mailman/listinfo/r-pack

Re: [R-pkg-devel] Using ggplot2 within another package

2021-04-22 Thread Kevin R. Coombes
Thanks.

Obviously, long. long ago, (in a galaxy not far enough away), Paul's 
suggestion of using "aes_string" was the correct one, since "aes" uses 
non-standard evaluation. (And to quote somebody from an R fortune 
cookie, "The problem with non-standard evaluation is that it is 
non-standard.") But teh documentation at the end oft he link provided by 
Robert explivityl tells you not to do that, since "aes_string is 
deprecated".  And reading more carefully into the manual page for 
aes_string, one does indeed find the statement that the function is 
"soft deprecated". I'm not sure what that means, other than someone on 
the development team doesn't like it.

Instead, the vignette says you should
    importFrom("rlang", ".data")
in your NAMESPACE, and write
    ggplot(myData, aes(x = .data$myX, y = .data$myY))

And now my dinosaur question: That looks like using one non-standard 
hack to cover up the problems with another non-standard hack. Why the 
heck  is that any better for the developer than writing
    ggplot(myData, aes(x = myData$myX, y = myData$myY))

or using Dirk Eddelbuettel's suggestion of calling utils::globalVariables ??

It's time to tell those kids to get off of my lawn.
   Kevin

On 4/22/2021 4:45 PM, Robert M. Flight wrote:
> Kevin,
>
> This vignette from ggplot2 itself gives the "officially recommended" 
> ways to avoid the warnings from R CMD check
>
> https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html 
> <https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html>
>
> Cheers,
>
> -Robert
>
> On Thu, Apr 22, 2021 at 4:39 PM Paul SAVARY 
> mailto:paul.sav...@univ-fcomte.fr>> wrote:
>
> Hi Kevin,
>
> I was faced to the same problem and I used 'aes_string()' instead
> of 'aes()'. You can then just write the name of the columns
> containing the data to plot as character strings.
>
> Example:
>
> myPlot <- function(myData, ...) {
>     # get ready
>     ggplot(myData, aes_string(x = "myX", y = "myY")) +
>        # add my decorations
>        theme_bw()
> }
>
> It is probably already the case for your function but you need to
> include #' @import ggplot2 in your function preamble (if I am not
> wrong).
>
> Kind regards
> Paul
>
>     ----- Mail original -----
> De: "Kevin R. Coombes"  <mailto:kevin.r.coom...@gmail.com>>
> À: "r-package-devel"  <mailto:r-package-devel@r-project.org>>
> Envoyé: Jeudi 22 Avril 2021 22:28:55
> Objet: [R-pkg-devel] Using ggplot2 within another package
>
> Hi,
>
> I'm trying to help clean up an R package for someone else to
> submit to
> CRAN. He has used ggplot2 to implement a plotting function for the
> kinds
> of things that his packages generates. His plotting routine basically
> looks like (after changing names to protect the innocent):
>
> myPlot <- fucntion(myData, ...) {
>     # get ready
>     ggplot(myData, aes(x = myX, y = myY)) +
>    # add my decorations
>    theme_bw()
> }
>
> Of course, "R CMD check --as-cran" complains that there is no global
> binding for "myX" or "myY" since they are columns defined in the
> data.frame "myData".
>
> What is the best way to work around this issue?
>
> Of course, dinosaurs like myself might be tempted to suggest just
> using
> plain old "plot", so I don't need to see those suggestions.
>
> Do I just ignore the usual ggplot conventions and write "myData$myX"
> inside "aes"  in order to appease the CRAN checker? Or is there some
> tidy-er way to solve this problem?
>
> Thanks,
>    Kevin
>
> __
> R-package-devel@r-project.org
> <mailto:R-package-devel@r-project.org> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> <https://stat.ethz.ch/mailman/listinfo/r-package-devel>
>
> __
> R-package-devel@r-project.org
> <mailto:R-package-devel@r-project.org> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> <https://stat.ethz.ch/mailman/listinfo/r-package-devel>
>


[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Using ggplot2 within another package

2021-04-22 Thread Dirk Eddelbuettel


On 22 April 2021 at 16:28, Kevin R. Coombes wrote:
| I'm trying to help clean up an R package for someone else to submit to 
| CRAN. He has used ggplot2 to implement a plotting function for the kinds 
| of things that his packages generates. His plotting routine basically 
| looks like (after changing names to protect the innocent):
| 
| myPlot <- fucntion(myData, ...) {
|     # get ready
|     ggplot(myData, aes(x = myX, y = myY)) +
|    # add my decorations
|    theme_bw()
| }
| 
| Of course, "R CMD check --as-cran" complains that there is no global 
| binding for "myX" or "myY" since they are columns defined in the 
| data.frame "myData".
| 
| What is the best way to work around this issue?

You can use the globalVariables() function to tell R about them:

   utils::globalVariables(c("myX", "myY"))

Dirk

-- 
https://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Using ggplot2 within another package

2021-04-22 Thread Robert M. Flight
Kevin,

This vignette from ggplot2 itself gives the "officially recommended" ways
to avoid the warnings from R CMD check

https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html

Cheers,

-Robert

On Thu, Apr 22, 2021 at 4:39 PM Paul SAVARY 
wrote:

> Hi Kevin,
>
> I was faced to the same problem and I used 'aes_string()' instead of
> 'aes()'. You can then just write the name of the columns containing the
> data to plot as character strings.
>
> Example:
>
> myPlot <- function(myData, ...) {
> # get ready
> ggplot(myData, aes_string(x = "myX", y = "myY")) +
># add my decorations
>theme_bw()
> }
>
> It is probably already the case for your function but you need to include
> #' @import ggplot2 in your function preamble (if I am not wrong).
>
> Kind regards
> Paul
>
> - Mail original -
> De: "Kevin R. Coombes" 
> À: "r-package-devel" 
> Envoyé: Jeudi 22 Avril 2021 22:28:55
> Objet: [R-pkg-devel] Using ggplot2 within another package
>
> Hi,
>
> I'm trying to help clean up an R package for someone else to submit to
> CRAN. He has used ggplot2 to implement a plotting function for the kinds
> of things that his packages generates. His plotting routine basically
> looks like (after changing names to protect the innocent):
>
> myPlot <- fucntion(myData, ...) {
> # get ready
> ggplot(myData, aes(x = myX, y = myY)) +
># add my decorations
>theme_bw()
> }
>
> Of course, "R CMD check --as-cran" complains that there is no global
> binding for "myX" or "myY" since they are columns defined in the
> data.frame "myData".
>
> What is the best way to work around this issue?
>
> Of course, dinosaurs like myself might be tempted to suggest just using
> plain old "plot", so I don't need to see those suggestions.
>
> Do I just ignore the usual ggplot conventions and write "myData$myX"
> inside "aes"  in order to appease the CRAN checker? Or is there some
> tidy-er way to solve this problem?
>
> Thanks,
>Kevin
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

[[alternative HTML version deleted]]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Using ggplot2 within another package

2021-04-22 Thread Paul SAVARY
Hi Kevin,

I was faced to the same problem and I used 'aes_string()' instead of 'aes()'. 
You can then just write the name of the columns containing the data to plot as 
character strings.

Example:

myPlot <- function(myData, ...) {
# get ready
ggplot(myData, aes_string(x = "myX", y = "myY")) +
   # add my decorations
   theme_bw()
}

It is probably already the case for your function but you need to include #' 
@import ggplot2 in your function preamble (if I am not wrong).

Kind regards
Paul

- Mail original -
De: "Kevin R. Coombes" 
À: "r-package-devel" 
Envoyé: Jeudi 22 Avril 2021 22:28:55
Objet: [R-pkg-devel] Using ggplot2 within another package

Hi,

I'm trying to help clean up an R package for someone else to submit to 
CRAN. He has used ggplot2 to implement a plotting function for the kinds 
of things that his packages generates. His plotting routine basically 
looks like (after changing names to protect the innocent):

myPlot <- fucntion(myData, ...) {
    # get ready
    ggplot(myData, aes(x = myX, y = myY)) +
   # add my decorations
   theme_bw()
}

Of course, "R CMD check --as-cran" complains that there is no global 
binding for "myX" or "myY" since they are columns defined in the 
data.frame "myData".

What is the best way to work around this issue?

Of course, dinosaurs like myself might be tempted to suggest just using 
plain old "plot", so I don't need to see those suggestions.

Do I just ignore the usual ggplot conventions and write "myData$myX" 
inside "aes"  in order to appease the CRAN checker? Or is there some 
tidy-er way to solve this problem?

Thanks,
   Kevin

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


[R-pkg-devel] Using ggplot2 within another package

2021-04-22 Thread Kevin R. Coombes

Hi,

I'm trying to help clean up an R package for someone else to submit to 
CRAN. He has used ggplot2 to implement a plotting function for the kinds 
of things that his packages generates. His plotting routine basically 
looks like (after changing names to protect the innocent):


myPlot <- fucntion(myData, ...) {
   # get ready
   ggplot(myData, aes(x = myX, y = myY)) +
  # add my decorations
  theme_bw()
}

Of course, "R CMD check --as-cran" complains that there is no global 
binding for "myX" or "myY" since they are columns defined in the 
data.frame "myData".


What is the best way to work around this issue?

Of course, dinosaurs like myself might be tempted to suggest just using 
plain old "plot", so I don't need to see those suggestions.


Do I just ignore the usual ggplot conventions and write "myData$myX" 
inside "aes"  in order to appease the CRAN checker? Or is there some 
tidy-er way to solve this problem?


Thanks,
  Kevin

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel