Rmarkdown won't knit (stumbles on googlesheets) when moved to a different directory

This is a pretty weird issue I'm having and I don't quite get it.

I have an rmarkdown file in my main R directory. It uses library (googlesheets) as one of the packages. Nothing much. It is fine and it works.

When I'm trying to save this file in my blogdown site repository, it starts to misbehave: it stops at the googlesheets step. I tried copying the file, or copying the code and saving as a new file, running inside and outside of the project...

The error I get is:
Quitting from lines 9-17 (cv.Rmd) Error in httpuv::startServer(use$host, use$port, list(call = listen)) : Failed to create server Calls: <Anonymous> ... init_oauth2.0 -> oauth_authorize -> oauth_listener -> <Anonymous>

OBVIOUSLY, I've restarted R session. One doc knits and the other doesn't. They are IDENTICAL. I just don't get it.

Any ideas?
Also, what kind of reproducible example I could provide, given the fact that it works and doesn't work on my machine at the same time?

googlesheets is presumably accessing a cached OAuth token that lives in a cache file in the original directory of execution. At some point you went to the browser and authorized googlesheets to deal with your Google account.

If you move the code, you also need to make that token available in the new place. There are many ways to do that, so maybe you can explain more about what you want to do.


Thank you!
I'm trying to run save an .Rmd document in one of the folders of my blogdown static blog. When saved in any of the folders under that project - the Rmd file won't knit and throws an above-mentioned error.

When I'm saving the file in any other directory - it knits just fine.
gs_auth() runs from a console, but doesn't run if it is a part of the file that is saved in a blogdown site directory.

Not sure if I make any sense...

I actually found your guide on this and reading it now. Thanks!