ropensci / vcr

Record HTTP calls and replay them
https://docs.ropensci.org/vcr
Other
77 stars 12 forks source link

Could one use vcr for vignettes? #150

Open maelle opened 4 years ago

maelle commented 4 years ago

And if so how could the setup work? Could there be a vcr knitr engine, so one would write

```vcr
my code with http requests


and fixtures would be saved somewhere?
sckott commented 4 years ago

i know less than nothing about knitr engines, so can't help there, but i don't see why one couldn't use vcr for vignettes. i guess there's caching in vignettes already, so would the use case be that a person would want the code in the vignette to run rather than being fully cached except wanting the HTTP requests/responses to be cached so those don't fail?

maelle commented 4 years ago

right not sure how much it brings compared to knitr caching :thinking:

sckott commented 4 years ago

it's probably a good thing to have all non http request code run each time as long as it isn't super long time in case any dependencies/pkg code changes?

sckott commented 4 years ago

see also #20

maelle commented 4 years ago

it's probably a good thing to have all non http request code run each time as long as it isn't super long time in case any dependencies/pkg code changes?

Right.

A downside I was thinking about is the size of cassettes but maybe one could re-use some of the test cassettes to have less cassettes overall. :thinking:

sckott commented 4 years ago

maybe one could re-use some of the test cassettes

could definitely try this. though what if a test cassette is quite old, and the package maintainer doesn't realise this?

maelle commented 4 years ago

then they should use re-record :wink: but yeah you're right.

sckott commented 4 years ago

true

maelle commented 3 years ago

What httptest supports https://enpiar.com/r/httptest/articles/vignettes.html

maelle commented 3 years ago

with vcr I suppose it'd mean running inject_cassette() at the beginning of the vignette and eject_cassette() at the end.

sckott commented 3 years ago

yeah, that would work

dtm2451 commented 3 years ago

Can I ask if there's been progress on this front?

I've been using vcr for testing my package, and it's been pretty easy, so thanks so much for a wonderful package!

I do think it would be helpful to add automated stubbing for vignettes without a need for too much extra code! inject/eject logic sounds good to (naive) me.

sckott commented 3 years ago

Thanks for the bump @dtm2451 And thx for using the pkg.

In the latest version on cran, now the insert_cassette()/eject_cassette() workflow works, so you can start using vcr in your vignette by running insert_cassette() and then stop using it somewhere else with eject_cassette() - you could hide those in the output of the vignette so reader doesn't know its happening

And for location of files, set up with vcr_configure() https://docs.ropensci.org/vcr/reference/vcr_configure.html

Let us know if it works!

dtm2451 commented 3 years ago

Worked! Simple to set up based off of the vcr_configure() code I already had for testing, & I was able to knit my vignette with my internet connection turned off after running it once with my internet on. Entire R CMD Check process worked with internet off =).

maelle commented 3 years ago

Would you mind sharing a link to your package?

sckott commented 3 years ago

Great, glad it works!