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

dependson another chuck which has cache=F behaves unexpectedly. #431

Closed
ghostwheel opened this issue Nov 29, 2012 · 4 comments

Comments

Projects
None yet
2 participants
@ghostwheel
Copy link

commented Nov 29, 2012

It seems that if I depend on a chunk which has cache=F, then updates never happen, whereas I would expect updates to always happen.

Here's an example:

{r chunk1}
a=20


{r chunk2, cache=TRUE, dependson='chunk1'}
plot(1:a)

changing 'a' in the 1st chunk has no effect. But if the first chunk had cache=T, things would work as expected.

The place where this can be used is that if I do something like:

{r chunk0}
docache=F

{r chunk1, cache=docache}
a=40


{r chunk2, cache=TRUE, dependson='chunk1'}
plot(1:a)

where docache is a variable that says if I think this chunk should be recalculated or not. (I thought of doing conditional caching depending on whether a data file has changed or not....)

@yihui

This comment has been minimized.

Copy link
Owner

commented Nov 29, 2012

That is easy to solve -- just put cache=TRUE, whatever=a in the second chunk, then when a changes, the cached chunk will update accordingly.

It is not easy to detect changes in uncached chunks, and that is why it is currently not possible to depend on uncached chunks.

@ghostwheel

This comment has been minimized.

Copy link
Author

commented Nov 29, 2012

That's really nice. I can even do whatever=file.info("data.txt")$mtime to check if a file is updated.
You should add that to the cache explanation! But maybe display a warning or error when you depend on an
uncached chunk, since the behaviour is so unexpected...

@yihui

This comment has been minimized.

Copy link
Owner

commented Nov 29, 2012

I'm glad you also figured out the file.info() trick, which I have mentioned in the documentation. I need to organize the documentation better, though: http://yihui.name/knitr/demo/cache/ (see Even more stuff for cache?)

Recently I have been busy with writing a book on knitr, and this issue has been addressed in the book.

Thanks for the suggestion for a warning. That makes sense. I'll try to do it.

@yihui

This comment has been minimized.

Copy link
Owner

commented Dec 2, 2012

I have added a warning in the development version if you depend on uncached chunks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.