From murdoch@dunc@n @ending from gm@il@com  Mon Jul  9 17:37:50 2018
From: murdoch@dunc@n @ending from gm@il@com (Duncan Murdoch)
Date: Mon, 9 Jul 2018 11:37:50 -0400
Subject: [Rd] Parametrized Vignettest in R packages
In-Reply-To: <CAAjnpdhkSa2_-4yCMvM5pNPjdLem-D4MwM=UmNJrjTGeV8AQfQ@mail.gmail.com>
References: <CAAjnpdhaeX+=RXCmq3g7jwYQZanfvps1q5i5znmynAGqxb1MPw@mail.gmail.com>
 <129b8986-700f-20bc-fefd-b813df73d06c@gmail.com>
 <CAAjnpdikxuy=KW1OVQEsqkQRwX8VLfedqwxO9mWzZ=cnijx-ZA@mail.gmail.com>
 <cafaec59-174f-9259-4d5c-f963299cdf23@gmail.com>
 <CAAjnpdhkSa2_-4yCMvM5pNPjdLem-D4MwM=UmNJrjTGeV8AQfQ@mail.gmail.com>
Message-ID: <6ac69071-c1b9-a7df-b33c-3c9ab1a5c973@gmail.com>

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 <murdoch.duncan at gmail.com> 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 <murdoch.duncan at gmail.com> 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
>>>>>
>>>>
>>>
>>>
>>>
>>
> 
> 
>



[Rd] Parametrized Vignettest in R packages
Duncan Murdoch