Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vignettes: adding info on relative path and encoding #31

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions vignettes/vignettes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Getting started is easy. At the beginning of your R Markdown document, add this

changing `vignette-name` to something meaningful, such as the name of your `.Rmd` file. `start_vignette()` works by checking for the existence of a directory with the name you provided. If no directory exists, the vignette proceeds making real API requests and records the responses as fixtures inside the `vignette-name` directory (that is, it calls `start_capturing()`). If the directory does exists, great---you've previously recorded API responses, so it uses them, loading them with the same `use_mock_api()` mode you can use in your test suite.

Note that `start_vignette()` sets a path relative to your *current* working directory. When building the vignette for the first time (and recording the responses), your working directory should be the `vignettes` folder, *not* the root directory of your package. If this has worked properly, you will find the response in the folder `vignettes/vignette-name/0...` (and **not** in the folder `vignettes/0/...`).

> Curious about how these recording and mocking contexts work? See `vignettes("httptest")` for an overview; it's focused on testing rather than vignettes, but the mechanics are the same.

That's about it! It is a good idea to add an `end_vignette()` at the end of the document, like
Expand All @@ -37,6 +39,8 @@ This turns off the request recording or mocking and cleans up the R session stat

Note that these code chunks have `include=FALSE`. This prevents them from being printed in the resulting Markdown, HTML, PDF, or whatever format document you produce. They're doing work behind the scenes, so you don't need them to be shown to your readers.

When your requests have been recorded and saved as a sub-folder that corresponds to your `vignette-name` in the vignettes directory, they will be used for all subsequent runs of the vignette. However, it's always assumed that the stored files are encoded in utf-8. If your files have a different encoding, you may need to change this manually to utf-8 for httptest to work properly.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this. It sounds like you're describing a bug that should be addressed, not something to document.

FWIW looking at the source for save_response(), I don't see how you can get anything that isn't UTF-8 or plain ASCII, so I'd be interested to see a minimal reprex.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely see your point. I have some example code where I reproducibly run into the exact same issue on a win10 computer. As I currently don't have access to linux/mac machines, i'm not entirely sure if this leads to the same problem. I'll try to verify that and come back to you.


# Handling server state changes

If all your vignette does is query an API to get data from it, `start_vignette()` is all you need. Your actions don't change the state of anything on the server, so every time you make the same request (at least within your current session), you get the same response.
Expand Down