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

Notebook format #395

Closed
renkun-ken opened this issue Aug 13, 2020 · 3 comments
Closed

Notebook format #395

renkun-ken opened this issue Aug 13, 2020 · 3 comments

Comments

@renkun-ken
Copy link
Member

renkun-ken commented Aug 13, 2020

As I'm trying to implement the R Notebook using the Notebook API at #394 initiated by #378, the first question is

What is the format of R Notebook in VSCode?

From the perspective of API, we could read any file into a collection of markdown cells and R code cells. Currently, https://github.com/Ikuyadeu/vscode-R/pull/394/files#diff-896fa9128d2e83307ffcf26741d257d2R142-R212 implements a simple line-by-line reader from Rmd file. All R code chunks are treated as R code cells, and others are treated as markdown cells.

The Rmd format is easy to read and write but it does not store output inside the file. I've tried R Notebook in RStudio and I don't have time to investigate how it could recover the output when I open an R Notebook from a Rmd file.

As most VSCode Notebook examples implement, the notebook is a JSON file of all cells and metadata, which could preserve all information in a notebook including cells and outputs.

I'm wondering if we should also implement R Notebook as a JSON file to achieve this, and preserve the capability of reading/writing Rmd as a Notebook but does not preserve outputs?

@andycraig
Copy link
Collaborator

I had a quick look at the way RStudio R Notebooks save the output. Here are the relevant files from the .Rproj.user directory in a project that contains an R Notebooks test.Rmd, which has two R chunks:

└───shared
    └───notebooks
        │   patch-chunk-names
        │   paths
        │
        └───B5CE159A-test
            └───1
                └───s
                    │   chunks.json
                    │
                    ├───c68yx1b0064yu
                    │       000002.csv
                    │       000003.png
                    │
                    └───ccw2gfveoholl
                            000002.csv

The content of chunks.json is:

{"chunk_definitions":[{"chunk_id":"c68yx1b0064yu","expansion_state":0,"options":[],"row":11,"row_count":1,"visible":true},{"chunk_id":"ccw2gfveoholl","expansion_state":0,"options":[],"row":17,"row_count":1,"visible":true}],"doc_write_time":1597363618.19062}

It seems logical but figuring out the details could take a while, as you say.

I think the user should only need to know about the Rmd file. Having the 'actual' notebook be a JSON file sounds fine to me. I think it should be hidden from the user (e.g., saved in .Rproj.user). Then we could replace it later with an RStudio-compatible version if we wanted to.

From https://bookdown.org/yihui/rmarkdown/notebook.html#saving-and-sharing 'The document’s chunk outputs are also stored in an internal RStudio folder beneath the project’s .Rproj.user folder. If you work with a notebook but do not have a project open, the outputs are stored in the RStudio state folder in your home directory (the location of this folder varies between the desktop and the server)'.

@github-actions
Copy link

github-actions bot commented Jun 9, 2022

This issue is stale because it has been open for 365 days with no activity.

@github-actions github-actions bot added the stale label Jun 9, 2022
@github-actions
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants