Parametrized Vignettest in R packages

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Parametrized Vignettest in R packages

Witold E Wolski
Hello,

I have a package which includes some parameterized r-markdown report
which I would also like to build as package vignettes.

Is there a way to run the parameterized vignette creation with the
package build or package check?

Thank you

--
Witold Eryk Wolski

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Gabe Becker
Witold,

Vignettes, in the package sense, are and must be entirely self-contained as
far as I know. They are run automatically in completely clean R sessions.
I'm not sure a parameterized vignette makes a ton of sense within that
context.

Can you explain what you would want to have happen when the package is
built that would require parameterization?

~G

On Mon, Jul 2, 2018 at 7:30 AM, Witold E Wolski <[hidden email]> wrote:

> Hello,
>
> I have a package which includes some parameterized r-markdown report
> which I would also like to build as package vignettes.
>
> Is there a way to run the parameterized vignette creation with the
> package build or package check?
>
> Thank you
>
> --
> Witold Eryk Wolski
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>


--
Gabriel Becker, Ph.D
Scientist
Bioinformatics and Computational Biology
Genentech Research

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Duncan Murdoch-2
In reply to this post by Witold E Wolski
On 02/07/2018 10:30 AM, Witold E Wolski wrote:
> Hello,
>
> I have a package which includes some parameterized r-markdown report
> which I would also like to build as package vignettes.
>
> Is there a way to run the parameterized vignette creation with the
> package build or package check?


Doesn't the usual method work?  You can specify defaults for parameters
in the YAML header; I'd expect those to be the parameter values that get
used.

You can give instructions to your users on how to rebuild the reports
with different parameters.

Duncan Murdoch

>
> Thank you
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Duncan Murdoch-2
In reply to this post by Gabe Becker
On 02/07/2018 10:34 AM, Gabe Becker wrote:
> Witold,
>
> Vignettes, in the package sense, are and must be entirely self-contained as
> far as I know. They are run automatically in completely clean R sessions.
> I'm not sure a parameterized vignette makes a ton of sense within that
> context.

The defaults for parameters are contained in the source, so a vignette
using default parameter values would be completely self-contained.

It seems like a good way to document parameterized reports:  Include one
as a vignette that has more explanation about what the parameters mean,
how they are used, etc.  Then users can try it out with new parameter
values before customizing it to their own needs.

Duncan Murdoch

>
> Can you explain what you would want to have happen when the package is
> built that would require parameterization?
>
> ~G
>
> On Mon, Jul 2, 2018 at 7:30 AM, Witold E Wolski <[hidden email]> wrote:
>
>> Hello,
>>
>> I have a package which includes some parameterized r-markdown report
>> which I would also like to build as package vignettes.
>>
>> Is there a way to run the parameterized vignette creation with the
>> package build or package check?
>>
>> Thank you
>>
>> --
>> Witold Eryk Wolski
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Witold E Wolski
In reply to this post by Duncan Murdoch-2
Hello,

Thank you for the questions as well as remaining me of the default
parameters in the yaml session.
Indeed this seems to be the solution.


But how would I assign package data as a default parameter?
So originally I thought to render the markdown with :

<code>
data(sample_analysis)
data(skylineconfig)
x <- rmarkdown::render("report.Rmd", output_format = "html_document",
                      params = list(data = sample_analysis,
                                    configuration =
skylineconfig),envir = new.env())
<code>

I do not think I can write:

params:
  configuration: !r data(sample_analysis)
  data: !r data(skylineconfig)

since data does not return the package just puts them in the env as a
side effect. Is there a different base function to achieve it.


Thank you
Witek




On 2 July 2018 at 16:56, Duncan Murdoch <[hidden email]> wrote:

> On 02/07/2018 10:30 AM, Witold E Wolski wrote:
>>
>> Hello,
>>
>> I have a package which includes some parameterized r-markdown report
>> which I would also like to build as package vignettes.
>>
>> Is there a way to run the parameterized vignette creation with the
>> package build or package check?
>
>
>
> Doesn't the usual method work?  You can specify defaults for parameters in
> the YAML header; I'd expect those to be the parameter values that get used.
>
> You can give instructions to your users on how to rebuild the reports with
> different parameters.
>
> Duncan Murdoch
>
>>
>> Thank you
>>
>



--
Witold Eryk Wolski

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Duncan Murdoch-2
On 02/07/2018 11:22 AM, Witold E Wolski wrote:

> Hello,
>
> Thank you for the questions as well as remaining me of the default
> parameters in the yaml session.
> Indeed this seems to be the solution.
>
>
> But how would I assign package data as a default parameter?
> So originally I thought to render the markdown with :
>
> <code>
> data(sample_analysis)
> data(skylineconfig)
> x <- rmarkdown::render("report.Rmd", output_format = "html_document",
>                        params = list(data = sample_analysis,
>                                      configuration =
> skylineconfig),envir = new.env())
> <code>
>
> I do not think I can write:
>
> params:
>    configuration: !r data(sample_analysis)
>    data: !r data(skylineconfig)
>
> since data does not return the package just puts them in the env as a
> side effect. Is there a different base function to achieve it.

I think you could use

  params:
   configuration: !r get(data(sample_analysis))
   data: !r get(data(skylineconfig))

but if that doesn't work, a longer version is

  params:
   configuration: !r {data(sample_analysis); sample_analysis}
   data: !r {data(skylineconfig); skylineconfig}

Duncan Murdoch

>
>
> Thank you
> Witek
>
>
>
>
> On 2 July 2018 at 16:56, Duncan Murdoch <[hidden email]> wrote:
>> On 02/07/2018 10:30 AM, Witold E Wolski wrote:
>>>
>>> Hello,
>>>
>>> I have a package which includes some parameterized r-markdown report
>>> which I would also like to build as package vignettes.
>>>
>>> Is there a way to run the parameterized vignette creation with the
>>> package build or package check?
>>
>>
>>
>> Doesn't the usual method work?  You can specify defaults for parameters in
>> the YAML header; I'd expect those to be the parameter values that get used.
>>
>> You can give instructions to your users on how to rebuild the reports with
>> different parameters.
>>
>> Duncan Murdoch
>>
>>>
>>> Thank you
>>>
>>
>
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Witold E Wolski
Dear Duncan,

Following your advice (Thank you for it) I did include into the vignettes
params:
  configuration: !r get(data(sample_analysis))
  data: !r get(data(skylineconfig))

And everything seemed (see below) to work fine.
devtools::build_vignettes() builds the vignettes.

Runs with NO error. By this the .Rmd file, html file and corresponding
.R files is being placed into the inst/doc directory.

However, when I did want to check the package by running
devtools::check(build_args="--no-build-vignettes")

The following warning is shown:

Warning: parse error in file
'C:/Users/wolski/AppData/Local/Temp/Rtmp4QanHv/SRMService.Rcheck/SRMService/doc/tr_srm_summary.R':
/Users/wolski/AppData/Local/Temp/Rtmp4QanHv/SRMService.Rcheck/SRMService/doc/tr_srm_summary.R:2:22:
unexpected '<'
1: params <-
2: list(configuration = <

This is how the start of the .R file produced from the vignette looks like.

params <-
list(configuration = <environment>, data = structure(list(protein_Id =
c("CiRT standards",

I am worried that this is the end of this road with parameterized
vignettes then? What do you think?

regards
Witek





On 2 July 2018 at 18:21, Duncan Murdoch <[hidden email]> wrote:

> On 02/07/2018 11:22 AM, Witold E Wolski wrote:
>>
>> Hello,
>>
>> Thank you for the questions as well as remaining me of the default
>> parameters in the yaml session.
>> Indeed this seems to be the solution.
>>
>>
>> But how would I assign package data as a default parameter?
>> So originally I thought to render the markdown with :
>>
>> <code>
>> data(sample_analysis)
>> data(skylineconfig)
>> x <- rmarkdown::render("report.Rmd", output_format = "html_document",
>>                        params = list(data = sample_analysis,
>>                                      configuration =
>> skylineconfig),envir = new.env())
>> <code>
>>
>> I do not think I can write:
>>
>> params:
>>    configuration: !r data(sample_analysis)
>>    data: !r data(skylineconfig)
>>
>> since data does not return the package just puts them in the env as a
>> side effect. Is there a different base function to achieve it.
>
>
> I think you could use
>
>  params:
>   configuration: !r get(data(sample_analysis))
>   data: !r get(data(skylineconfig))
>
> but if that doesn't work, a longer version is
>
>  params:
>   configuration: !r {data(sample_analysis); sample_analysis}
>   data: !r {data(skylineconfig); skylineconfig}
>
> Duncan Murdoch
>
>
>>
>>
>> Thank you
>> Witek
>>
>>
>>
>>
>> On 2 July 2018 at 16:56, Duncan Murdoch <[hidden email]> wrote:
>>>
>>> On 02/07/2018 10:30 AM, Witold E Wolski wrote:
>>>>
>>>>
>>>> Hello,
>>>>
>>>> I have a package which includes some parameterized r-markdown report
>>>> which I would also like to build as package vignettes.
>>>>
>>>> Is there a way to run the parameterized vignette creation with the
>>>> package build or package check?
>>>
>>>
>>>
>>>
>>> Doesn't the usual method work?  You can specify defaults for parameters
>>> in
>>> the YAML header; I'd expect those to be the parameter values that get
>>> used.
>>>
>>> You can give instructions to your users on how to rebuild the reports
>>> with
>>> different parameters.
>>>
>>> Duncan Murdoch
>>>
>>>>
>>>> Thank you
>>>>
>>>
>>
>>
>>
>



--
Witold Eryk Wolski

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Duncan Murdoch-2
On 09/07/2018 8:49 AM, Witold E Wolski wrote:

> Dear Duncan,
>
> Following your advice (Thank you for it) I did include into the vignettes
> params:
>    configuration: !r get(data(sample_analysis))
>    data: !r get(data(skylineconfig))
>
> And everything seemed (see below) to work fine.
> devtools::build_vignettes() builds the vignettes.
>
> Runs with NO error. By this the .Rmd file, html file and corresponding
> .R files is being placed into the inst/doc directory.
>
> However, when I did want to check the package by running
> devtools::check(build_args="--no-build-vignettes")
>
> The following warning is shown:
>
> Warning: parse error in file
> 'C:/Users/wolski/AppData/Local/Temp/Rtmp4QanHv/SRMService.Rcheck/SRMService/doc/tr_srm_summary.R':
> /Users/wolski/AppData/Local/Temp/Rtmp4QanHv/SRMService.Rcheck/SRMService/doc/tr_srm_summary.R:2:22:
> unexpected '<'
> 1: params <-
> 2: list(configuration = <
>
> This is how the start of the .R file produced from the vignette looks like.
>
> params <-
> list(configuration = <environment>, data = structure(list(protein_Id =
> c("CiRT standards",
>
> I am worried that this is the end of this road with parameterized
> vignettes then? What do you think?

Interesting.  The issue is that the value being assigned to
configuration is an environment, and whatever code produces those lines
in tr_srm_summary.R isn't deparsing it into something parseable.  (This
isn't a big surprise:  dput and deparse both fail at that.)

I'd guess a solution is not to save sample_analysis as an environment,
but maybe you didn't know you were doing that since some other
structures are implemented as environments.

Perhaps you could use

configuration: !r as.list(get(data(sample_analysis)))

and then when you need to use it, convert it back to the original type?

Duncan Murdoch

>
> regards
> Witek
>
>
>
>
>
> On 2 July 2018 at 18:21, Duncan Murdoch <[hidden email]> wrote:
>> On 02/07/2018 11:22 AM, Witold E Wolski wrote:
>>>
>>> Hello,
>>>
>>> Thank you for the questions as well as remaining me of the default
>>> parameters in the yaml session.
>>> Indeed this seems to be the solution.
>>>
>>>
>>> But how would I assign package data as a default parameter?
>>> So originally I thought to render the markdown with :
>>>
>>> <code>
>>> data(sample_analysis)
>>> data(skylineconfig)
>>> x <- rmarkdown::render("report.Rmd", output_format = "html_document",
>>>                         params = list(data = sample_analysis,
>>>                                       configuration =
>>> skylineconfig),envir = new.env())
>>> <code>
>>>
>>> I do not think I can write:
>>>
>>> params:
>>>     configuration: !r data(sample_analysis)
>>>     data: !r data(skylineconfig)
>>>
>>> since data does not return the package just puts them in the env as a
>>> side effect. Is there a different base function to achieve it.
>>
>>
>> I think you could use
>>
>>   params:
>>    configuration: !r get(data(sample_analysis))
>>    data: !r get(data(skylineconfig))
>>
>> but if that doesn't work, a longer version is
>>
>>   params:
>>    configuration: !r {data(sample_analysis); sample_analysis}
>>    data: !r {data(skylineconfig); skylineconfig}
>>
>> Duncan Murdoch
>>
>>
>>>
>>>
>>> Thank you
>>> Witek
>>>
>>>
>>>
>>>
>>> On 2 July 2018 at 16:56, Duncan Murdoch <[hidden email]> wrote:
>>>>
>>>> On 02/07/2018 10:30 AM, Witold E Wolski wrote:
>>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> I have a package which includes some parameterized r-markdown report
>>>>> which I would also like to build as package vignettes.
>>>>>
>>>>> Is there a way to run the parameterized vignette creation with the
>>>>> package build or package check?
>>>>
>>>>
>>>>
>>>>
>>>> Doesn't the usual method work?  You can specify defaults for parameters
>>>> in
>>>> the YAML header; I'd expect those to be the parameter values that get
>>>> used.
>>>>
>>>> You can give instructions to your users on how to rebuild the reports
>>>> with
>>>> different parameters.
>>>>
>>>> Duncan Murdoch
>>>>
>>>>>
>>>>> Thank you
>>>>>
>>>>
>>>
>>>
>>>
>>
>
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Yihui Xie-2
So far you haven't provided a reproducible example yet. I wonder what
exactly the object `sample_analysis` is. Sounds like it is an
environment. If that is the case, devtools::build_vignettes() will
tangle (for the meaning of "tangle", see ?tools::buildVignette) your
vignette into an invalid R script. Environments cannot be represented
via dput(), so knitr's purl() (eventually called by the vignette
engine) cannot really create a valid R script when your vignette
contains `params` that uses environment values. Most other types of
values should be fine.

Regards,
Yihui
--
https://yihui.name


On Mon, Jul 9, 2018 at 10:37 AM, Duncan Murdoch
<[hidden email]> wrote:

> On 09/07/2018 8:49 AM, Witold E Wolski wrote:
>>
>> Dear Duncan,
>>
>> Following your advice (Thank you for it) I did include into the vignettes
>> params:
>>    configuration: !r get(data(sample_analysis))
>>    data: !r get(data(skylineconfig))
>>
>> And everything seemed (see below) to work fine.
>> devtools::build_vignettes() builds the vignettes.
>>
>> Runs with NO error. By this the .Rmd file, html file and corresponding
>> .R files is being placed into the inst/doc directory.
>>
>> However, when I did want to check the package by running
>> devtools::check(build_args="--no-build-vignettes")
>>
>> The following warning is shown:
>>
>> Warning: parse error in file
>>
>> 'C:/Users/wolski/AppData/Local/Temp/Rtmp4QanHv/SRMService.Rcheck/SRMService/doc/tr_srm_summary.R':
>>
>> /Users/wolski/AppData/Local/Temp/Rtmp4QanHv/SRMService.Rcheck/SRMService/doc/tr_srm_summary.R:2:22:
>> unexpected '<'
>> 1: params <-
>> 2: list(configuration = <
>>
>> This is how the start of the .R file produced from the vignette looks
>> like.
>>
>> params <-
>> list(configuration = <environment>, data = structure(list(protein_Id =
>> c("CiRT standards",
>>
>> I am worried that this is the end of this road with parameterized
>> vignettes then? What do you think?
>
>
> Interesting.  The issue is that the value being assigned to configuration is
> an environment, and whatever code produces those lines in tr_srm_summary.R
> isn't deparsing it into something parseable.  (This isn't a big surprise:
> dput and deparse both fail at that.)
>
> I'd guess a solution is not to save sample_analysis as an environment, but
> maybe you didn't know you were doing that since some other structures are
> implemented as environments.
>
> Perhaps you could use
>
> configuration: !r as.list(get(data(sample_analysis)))
>
> and then when you need to use it, convert it back to the original type?
>
> Duncan Murdoch
>>
>>
>> regards
>> Witek
>>
>>
>>
>>
>>
>> On 2 July 2018 at 18:21, Duncan Murdoch <[hidden email]> wrote:
>>>
>>> On 02/07/2018 11:22 AM, Witold E Wolski wrote:
>>>>
>>>>
>>>> Hello,
>>>>
>>>> Thank you for the questions as well as remaining me of the default
>>>> parameters in the yaml session.
>>>> Indeed this seems to be the solution.
>>>>
>>>>
>>>> But how would I assign package data as a default parameter?
>>>> So originally I thought to render the markdown with :
>>>>
>>>> <code>
>>>> data(sample_analysis)
>>>> data(skylineconfig)
>>>> x <- rmarkdown::render("report.Rmd", output_format = "html_document",
>>>>                         params = list(data = sample_analysis,
>>>>                                       configuration =
>>>> skylineconfig),envir = new.env())
>>>> <code>
>>>>
>>>> I do not think I can write:
>>>>
>>>> params:
>>>>     configuration: !r data(sample_analysis)
>>>>     data: !r data(skylineconfig)
>>>>
>>>> since data does not return the package just puts them in the env as a
>>>> side effect. Is there a different base function to achieve it.
>>>
>>>
>>>
>>> I think you could use
>>>
>>>   params:
>>>    configuration: !r get(data(sample_analysis))
>>>    data: !r get(data(skylineconfig))
>>>
>>> but if that doesn't work, a longer version is
>>>
>>>   params:
>>>    configuration: !r {data(sample_analysis); sample_analysis}
>>>    data: !r {data(skylineconfig); skylineconfig}
>>>
>>> Duncan Murdoch
>>>
>>>
>>>>
>>>>
>>>> Thank you
>>>> Witek
>>>>
>>>>
>>>>
>>>>
>>>> On 2 July 2018 at 16:56, Duncan Murdoch <[hidden email]>
>>>> wrote:
>>>>>
>>>>>
>>>>> On 02/07/2018 10:30 AM, Witold E Wolski wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I have a package which includes some parameterized r-markdown report
>>>>>> which I would also like to build as package vignettes.
>>>>>>
>>>>>> Is there a way to run the parameterized vignette creation with the
>>>>>> package build or package check?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Doesn't the usual method work?  You can specify defaults for parameters
>>>>> in
>>>>> the YAML header; I'd expect those to be the parameter values that get
>>>>> used.
>>>>>
>>>>> You can give instructions to your users on how to rebuild the reports
>>>>> with
>>>>> different parameters.
>>>>>
>>>>> Duncan Murdoch
>>>>>
>>>>>>
>>>>>> Thank you
>>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>
>>
>>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Duncan Murdoch-2
On 09/07/2018 12:24 PM, Yihui Xie wrote:
> So far you haven't provided a reproducible example yet. I wonder what
> exactly the object `sample_analysis` is. Sounds like it is an
> environment. If that is the case, devtools::build_vignettes() will
> tangle (for the meaning of "tangle", see ?tools::buildVignette) your
> vignette into an invalid R script. Environments cannot be represented
> via dput(), so knitr's purl() (eventually called by the vignette
> engine) cannot really create a valid R script when your vignette
> contains `params` that uses environment values. Most other types of
> values should be fine.

One possibility is to delay evaluation of the parameter.  For example
putting

params:
   configuration:  !r quote(get(data(sample_analysis)))

in the YAML will set configuration to the expression needed to get the
environment;

     eval(params$configuration)

gives you the environment itself.

Duncan Murdoch




>
> Regards,
> Yihui
> --
> https://yihui.name
>
>
> On Mon, Jul 9, 2018 at 10:37 AM, Duncan Murdoch
> <[hidden email]> wrote:
>> On 09/07/2018 8:49 AM, Witold E Wolski wrote:
>>>
>>> Dear Duncan,
>>>
>>> Following your advice (Thank you for it) I did include into the vignettes
>>> params:
>>>     configuration: !r get(data(sample_analysis))
>>>     data: !r get(data(skylineconfig))
>>>
>>> And everything seemed (see below) to work fine.
>>> devtools::build_vignettes() builds the vignettes.
>>>
>>> Runs with NO error. By this the .Rmd file, html file and corresponding
>>> .R files is being placed into the inst/doc directory.
>>>
>>> However, when I did want to check the package by running
>>> devtools::check(build_args="--no-build-vignettes")
>>>
>>> The following warning is shown:
>>>
>>> Warning: parse error in file
>>>
>>> 'C:/Users/wolski/AppData/Local/Temp/Rtmp4QanHv/SRMService.Rcheck/SRMService/doc/tr_srm_summary.R':
>>>
>>> /Users/wolski/AppData/Local/Temp/Rtmp4QanHv/SRMService.Rcheck/SRMService/doc/tr_srm_summary.R:2:22:
>>> unexpected '<'
>>> 1: params <-
>>> 2: list(configuration = <
>>>
>>> This is how the start of the .R file produced from the vignette looks
>>> like.
>>>
>>> params <-
>>> list(configuration = <environment>, data = structure(list(protein_Id =
>>> c("CiRT standards",
>>>
>>> I am worried that this is the end of this road with parameterized
>>> vignettes then? What do you think?
>>
>>
>> Interesting.  The issue is that the value being assigned to configuration is
>> an environment, and whatever code produces those lines in tr_srm_summary.R
>> isn't deparsing it into something parseable.  (This isn't a big surprise:
>> dput and deparse both fail at that.)
>>
>> I'd guess a solution is not to save sample_analysis as an environment, but
>> maybe you didn't know you were doing that since some other structures are
>> implemented as environments.
>>
>> Perhaps you could use
>>
>> configuration: !r as.list(get(data(sample_analysis)))
>>
>> and then when you need to use it, convert it back to the original type?
>>
>> Duncan Murdoch
>>>
>>>
>>> regards
>>> Witek
>>>
>>>
>>>
>>>
>>>
>>> On 2 July 2018 at 18:21, Duncan Murdoch <[hidden email]> wrote:
>>>>
>>>> On 02/07/2018 11:22 AM, Witold E Wolski wrote:
>>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> Thank you for the questions as well as remaining me of the default
>>>>> parameters in the yaml session.
>>>>> Indeed this seems to be the solution.
>>>>>
>>>>>
>>>>> But how would I assign package data as a default parameter?
>>>>> So originally I thought to render the markdown with :
>>>>>
>>>>> <code>
>>>>> data(sample_analysis)
>>>>> data(skylineconfig)
>>>>> x <- rmarkdown::render("report.Rmd", output_format = "html_document",
>>>>>                          params = list(data = sample_analysis,
>>>>>                                        configuration =
>>>>> skylineconfig),envir = new.env())
>>>>> <code>
>>>>>
>>>>> I do not think I can write:
>>>>>
>>>>> params:
>>>>>      configuration: !r data(sample_analysis)
>>>>>      data: !r data(skylineconfig)
>>>>>
>>>>> since data does not return the package just puts them in the env as a
>>>>> side effect. Is there a different base function to achieve it.
>>>>
>>>>
>>>>
>>>> I think you could use
>>>>
>>>>    params:
>>>>     configuration: !r get(data(sample_analysis))
>>>>     data: !r get(data(skylineconfig))
>>>>
>>>> but if that doesn't work, a longer version is
>>>>
>>>>    params:
>>>>     configuration: !r {data(sample_analysis); sample_analysis}
>>>>     data: !r {data(skylineconfig); skylineconfig}
>>>>
>>>> Duncan Murdoch
>>>>
>>>>
>>>>>
>>>>>
>>>>> Thank you
>>>>> Witek
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 2 July 2018 at 16:56, Duncan Murdoch <[hidden email]>
>>>>> wrote:
>>>>>>
>>>>>>
>>>>>> On 02/07/2018 10:30 AM, Witold E Wolski wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> I have a package which includes some parameterized r-markdown report
>>>>>>> which I would also like to build as package vignettes.
>>>>>>>
>>>>>>> Is there a way to run the parameterized vignette creation with the
>>>>>>> package build or package check?
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Doesn't the usual method work?  You can specify defaults for parameters
>>>>>> in
>>>>>> the YAML header; I'd expect those to be the parameter values that get
>>>>>> used.
>>>>>>
>>>>>> You can give instructions to your users on how to rebuild the reports
>>>>>> with
>>>>>> different parameters.
>>>>>>
>>>>>> Duncan Murdoch
>>>>>>
>>>>>>>
>>>>>>> Thank you
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Witold E Wolski
In reply to this post by Yihui Xie-2
Dear Yihui,

Thank you for the valuable questions.

sample_analysis is a "tibble" while
configuration is an "R6" class.
But I also have parametrized reports where I pass R reference classes
as arguments.

This is the Rmd yaml params part corresponding to the error message.

params:
  configuration:  !r get(data(skylineconfig))
  data: !r get(data(sample_analysis))

Might the R6 class which I pass to  configuration the source of the
problem here? I have heard somewhere that R6 uses environments to
implemented some features.



There is also a further problem I am encountering reproducible when
running devtools::install() or R CMD INSTALL

** installing vignettes
   'tr_srm_summary.Rmd' using 'UTF-8'
Warning in data(skylineconfig) : data set 'skylineconfig' not found
Error in get(data(skylineconfig)) : object 'skylineconfig' not found

This problem isn't happening when running
devtools::build_vignettes()

The Package install works however if I first build the vignettes with
devtools::build_vignettes() and than run R CMD INSTALL


I will be sending to you a link to a repository with a reproducible
example in a separate e-mail.

Kind regards
Witek

On 9 July 2018 at 18:24, Yihui Xie <[hidden email]> wrote:

> So far you haven't provided a reproducible example yet. I wonder what
> exactly the object `sample_analysis` is. Sounds like it is an
> environment. If that is the case, devtools::build_vignettes() will
> tangle (for the meaning of "tangle", see ?tools::buildVignette) your
> vignette into an invalid R script. Environments cannot be represented
> via dput(), so knitr's purl() (eventually called by the vignette
> engine) cannot really create a valid R script when your vignette
> contains `params` that uses environment values. Most other types of
> values should be fine.
>
> Regards,
> Yihui
> --
> https://yihui.name
>
>
> On Mon, Jul 9, 2018 at 10:37 AM, Duncan Murdoch
> <[hidden email]> wrote:
>> On 09/07/2018 8:49 AM, Witold E Wolski wrote:
>>>
>>> Dear Duncan,
>>>
>>> Following your advice (Thank you for it) I did include into the vignettes
>>> params:
>>>    configuration: !r get(data(sample_analysis))
>>>    data: !r get(data(skylineconfig))
>>>
>>> And everything seemed (see below) to work fine.
>>> devtools::build_vignettes() builds the vignettes.
>>>
>>> Runs with NO error. By this the .Rmd file, html file and corresponding
>>> .R files is being placed into the inst/doc directory.
>>>
>>> However, when I did want to check the package by running
>>> devtools::check(build_args="--no-build-vignettes")
>>>
>>> The following warning is shown:
>>>
>>> Warning: parse error in file
>>>
>>> 'C:/Users/wolski/AppData/Local/Temp/Rtmp4QanHv/SRMService.Rcheck/SRMService/doc/tr_srm_summary.R':
>>>
>>> /Users/wolski/AppData/Local/Temp/Rtmp4QanHv/SRMService.Rcheck/SRMService/doc/tr_srm_summary.R:2:22:
>>> unexpected '<'
>>> 1: params <-
>>> 2: list(configuration = <
>>>
>>> This is how the start of the .R file produced from the vignette looks
>>> like.
>>>
>>> params <-
>>> list(configuration = <environment>, data = structure(list(protein_Id =
>>> c("CiRT standards",
>>>
>>> I am worried that this is the end of this road with parameterized
>>> vignettes then? What do you think?
>>
>>
>> Interesting.  The issue is that the value being assigned to configuration is
>> an environment, and whatever code produces those lines in tr_srm_summary.R
>> isn't deparsing it into something parseable.  (This isn't a big surprise:
>> dput and deparse both fail at that.)
>>
>> I'd guess a solution is not to save sample_analysis as an environment, but
>> maybe you didn't know you were doing that since some other structures are
>> implemented as environments.
>>
>> Perhaps you could use
>>
>> configuration: !r as.list(get(data(sample_analysis)))
>>
>> and then when you need to use it, convert it back to the original type?
>>
>> Duncan Murdoch
>>>
>>>
>>> regards
>>> Witek
>>>
>>>
>>>
>>>
>>>
>>> On 2 July 2018 at 18:21, Duncan Murdoch <[hidden email]> wrote:
>>>>
>>>> On 02/07/2018 11:22 AM, Witold E Wolski wrote:
>>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> Thank you for the questions as well as remaining me of the default
>>>>> parameters in the yaml session.
>>>>> Indeed this seems to be the solution.
>>>>>
>>>>>
>>>>> But how would I assign package data as a default parameter?
>>>>> So originally I thought to render the markdown with :
>>>>>
>>>>> <code>
>>>>> data(sample_analysis)
>>>>> data(skylineconfig)
>>>>> x <- rmarkdown::render("report.Rmd", output_format = "html_document",
>>>>>                         params = list(data = sample_analysis,
>>>>>                                       configuration =
>>>>> skylineconfig),envir = new.env())
>>>>> <code>
>>>>>
>>>>> I do not think I can write:
>>>>>
>>>>> params:
>>>>>     configuration: !r data(sample_analysis)
>>>>>     data: !r data(skylineconfig)
>>>>>
>>>>> since data does not return the package just puts them in the env as a
>>>>> side effect. Is there a different base function to achieve it.
>>>>
>>>>
>>>>
>>>> I think you could use
>>>>
>>>>   params:
>>>>    configuration: !r get(data(sample_analysis))
>>>>    data: !r get(data(skylineconfig))
>>>>
>>>> but if that doesn't work, a longer version is
>>>>
>>>>   params:
>>>>    configuration: !r {data(sample_analysis); sample_analysis}
>>>>    data: !r {data(skylineconfig); skylineconfig}
>>>>
>>>> Duncan Murdoch
>>>>
>>>>
>>>>>
>>>>>
>>>>> Thank you
>>>>> Witek
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On 2 July 2018 at 16:56, Duncan Murdoch <[hidden email]>
>>>>> wrote:
>>>>>>
>>>>>>
>>>>>> On 02/07/2018 10:30 AM, Witold E Wolski wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Hello,
>>>>>>>
>>>>>>> I have a package which includes some parameterized r-markdown report
>>>>>>> which I would also like to build as package vignettes.
>>>>>>>
>>>>>>> Is there a way to run the parameterized vignette creation with the
>>>>>>> package build or package check?
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Doesn't the usual method work?  You can specify defaults for parameters
>>>>>> in
>>>>>> the YAML header; I'd expect those to be the parameter values that get
>>>>>> used.
>>>>>>
>>>>>> You can give instructions to your users on how to rebuild the reports
>>>>>> with
>>>>>> different parameters.
>>>>>>
>>>>>> Duncan Murdoch
>>>>>>
>>>>>>>
>>>>>>> Thank you
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel



--
Witold Eryk Wolski

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Duncan Murdoch-2
On 09/07/2018 3:24 PM, Witold E Wolski wrote:

> Dear Yihui,
>
> Thank you for the valuable questions.
>
> sample_analysis is a "tibble" while
> configuration is an "R6" class.
> But I also have parametrized reports where I pass R reference classes
> as arguments.
>
> This is the Rmd yaml params part corresponding to the error message.
>
> params:
>    configuration:  !r get(data(skylineconfig))
>    data: !r get(data(sample_analysis))
>
> Might the R6 class which I pass to  configuration the source of the
> problem here? I have heard somewhere that R6 uses environments to
> implemented some features.
>
>
>
> There is also a further problem I am encountering reproducible when
> running devtools::install() or R CMD INSTALL
>
> ** installing vignettes
>     'tr_srm_summary.Rmd' using 'UTF-8'
> Warning in data(skylineconfig) : data set 'skylineconfig' not found
> Error in get(data(skylineconfig)) : object 'skylineconfig' not found

You likely need to specify the package name, e.g.

data("skylineconfig", package = "yourpackage")

Also see my suggestion to use quote() to delay evaluation:

> params:
>    configuration:  !r quote(get(data(sample_analysis)))
>
> in the YAML will set configuration to the expression needed to get the
> environment;
>
>      eval(params$configuration)

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Witold E Wolski
Dear Duncan,

Was close to giving up to use the parameterized rmarkown as vignettes.
But your suggestions to use quote and eval, as well as to use the
package parameter in data
 made it work, with all devtools::install,check,build and
build_vignettes as well as with R CMD ... etc.
But most importantly it also still works with:
rmarkdown::render("vignettes/tr_srm_summary.Rmd",
params=list(configuration=skylineconfig, data=sample_analysis    ))

THANK YOU.

This is how my vignette header looks (see below) and it works.

---
title: "Titel"
author: "[hidden email]"
date: "`r Sys.Date()`"
output:
  pdf_document: default
  html_document: default
params:
  configuration:  !r quote(get(data(skylineconfig, package="myPackage")))
  data: !r quote(get(data(sample_analysis, package="myPackage")))
vignette: >
  %\VignetteIndexEntry{Summarize Peptide Level Measurements}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---


```{r setup, include=FALSE}
library(tidyverse)

knitr::opts_chunk$set(echo = FALSE, message=FALSE)
data <- eval(params$data)
configuration <- eval(params$configuration)
```

Have a great evening.

regards
Witek

On 9 July 2018 at 21:32, Duncan Murdoch <[hidden email]> wrote:

> On 09/07/2018 3:24 PM, Witold E Wolski wrote:
>>
>> Dear Yihui,
>>
>> Thank you for the valuable questions.
>>
>> sample_analysis is a "tibble" while
>> configuration is an "R6" class.
>> But I also have parametrized reports where I pass R reference classes
>> as arguments.
>>
>> This is the Rmd yaml params part corresponding to the error message.
>>
>> params:
>>    configuration:  !r get(data(skylineconfig))
>>    data: !r get(data(sample_analysis))
>>
>> Might the R6 class which I pass to  configuration the source of the
>> problem here? I have heard somewhere that R6 uses environments to
>> implemented some features.
>>
>>
>>
>> There is also a further problem I am encountering reproducible when
>> running devtools::install() or R CMD INSTALL
>>
>> ** installing vignettes
>>     'tr_srm_summary.Rmd' using 'UTF-8'
>> Warning in data(skylineconfig) : data set 'skylineconfig' not found
>> Error in get(data(skylineconfig)) : object 'skylineconfig' not found
>
>
> You likely need to specify the package name, e.g.
>
> data("skylineconfig", package = "yourpackage")
>
> Also see my suggestion to use quote() to delay evaluation:
>
>
>> params:
>>    configuration:  !r quote(get(data(sample_analysis)))
>>
>> in the YAML will set configuration to the expression needed to get the
>> environment;
>>
>>      eval(params$configuration)
>
>
> Duncan Murdoch



--
Witold Eryk Wolski

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Parametrized Vignettest in R packages

Yihui Xie-2
I wonder if get(data(foo, package="myPackage")) could be rewritten as
myPackage::foo. The latter will be a little more rigorous, because
data(foo) simply returns a character string "foo", so you are
essentially calling get ("foo"), and the default get(, inherits =
FALSE) may cause you trouble sometimes.

Anyway, the value returned by quote() can be represented when calling
dput(), so knitr can support it when generating the R script from the
vignette.

Another way to specify the params defaults could be:

---
params:
  foo: null
---

```{r}
if (is.null(params$foo)) params$foo = myPackage::foo
```

Regards,
Yihui
--
https://yihui.name


On Mon, Jul 9, 2018 at 3:11 PM, Witold E Wolski <[hidden email]> wrote:

> Dear Duncan,
>
> Was close to giving up to use the parameterized rmarkown as vignettes.
> But your suggestions to use quote and eval, as well as to use the
> package parameter in data
>  made it work, with all devtools::install,check,build and
> build_vignettes as well as with R CMD ... etc.
> But most importantly it also still works with:
> rmarkdown::render("vignettes/tr_srm_summary.Rmd",
> params=list(configuration=skylineconfig, data=sample_analysis    ))
>
> THANK YOU.
>
> This is how my vignette header looks (see below) and it works.
>
> ---
> title: "Titel"
> author: "[hidden email]"
> date: "`r Sys.Date()`"
> output:
>   pdf_document: default
>   html_document: default
> params:
>   configuration:  !r quote(get(data(skylineconfig, package="myPackage")))
>   data: !r quote(get(data(sample_analysis, package="myPackage")))
> vignette: >
>   %\VignetteIndexEntry{Summarize Peptide Level Measurements}
>   %\VignetteEngine{knitr::rmarkdown}
>   %\VignetteEncoding{UTF-8}
> ---
>
>
> ```{r setup, include=FALSE}
> library(tidyverse)
>
> knitr::opts_chunk$set(echo = FALSE, message=FALSE)
> data <- eval(params$data)
> configuration <- eval(params$configuration)
> ```
>
> Have a great evening.
>
> regards
> Witek
>
> On 9 July 2018 at 21:32, Duncan Murdoch <[hidden email]> wrote:
>> On 09/07/2018 3:24 PM, Witold E Wolski wrote:
>>>
>>> Dear Yihui,
>>>
>>> Thank you for the valuable questions.
>>>
>>> sample_analysis is a "tibble" while
>>> configuration is an "R6" class.
>>> But I also have parametrized reports where I pass R reference classes
>>> as arguments.
>>>
>>> This is the Rmd yaml params part corresponding to the error message.
>>>
>>> params:
>>>    configuration:  !r get(data(skylineconfig))
>>>    data: !r get(data(sample_analysis))
>>>
>>> Might the R6 class which I pass to  configuration the source of the
>>> problem here? I have heard somewhere that R6 uses environments to
>>> implemented some features.
>>>
>>>
>>>
>>> There is also a further problem I am encountering reproducible when
>>> running devtools::install() or R CMD INSTALL
>>>
>>> ** installing vignettes
>>>     'tr_srm_summary.Rmd' using 'UTF-8'
>>> Warning in data(skylineconfig) : data set 'skylineconfig' not found
>>> Error in get(data(skylineconfig)) : object 'skylineconfig' not found
>>
>>
>> You likely need to specify the package name, e.g.
>>
>> data("skylineconfig", package = "yourpackage")
>>
>> Also see my suggestion to use quote() to delay evaluation:
>>
>>
>>> params:
>>>    configuration:  !r quote(get(data(sample_analysis)))
>>>
>>> in the YAML will set configuration to the expression needed to get the
>>> environment;
>>>
>>>      eval(params$configuration)
>>
>>
>> Duncan Murdoch
>
>
>
> --
> Witold Eryk Wolski

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel