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

Convert Jupiter notebook to sandpaper (r-markdown) #3

Closed
sabaferdous12 opened this issue Feb 24, 2022 · 2 comments
Closed

Convert Jupiter notebook to sandpaper (r-markdown) #3

sabaferdous12 opened this issue Feb 24, 2022 · 2 comments

Comments

@sabaferdous12
Copy link
Collaborator

  1. try it on an existing notebook
  2. Adding styles/boxes
  3. Implement in sandpaper (where in folder structure n code)

https://rmarkdown.rstudio.com/docs/reference/convert_ipynb.html

@dpshelio
Copy link

dpshelio commented Apr 21, 2022

rmarkdwon:::convert_ipynb doesn't read title and other tags from the metadata, which it's where we could add the information.

On way to do that is by overwriting their ipynb_yaml function. In a hacky way we can do it as:

nb_file <- "sample.ipynb"

library('rmarkdown')
ipynb_yaml <- function(meta, input) {
  # default title and output format
  res <- list(
    title = paste0('This is mine "', input, '"'),
    output = 'html_document'
  )
  # currently only the `authors` field is supported
  authors <- unlist(lapply(meta$authors, `[[`, 'name'))
  if (length(authors) > 0) res[['author']] <- paste(authors, collapse = ', ')
  gsub('\n+$', '', yaml::as.yaml(res))
}
assignInNamespace("ipynb_yaml", ipynb_yaml, "rmarkdown",)

nb_rmd = rmarkdown:::convert_ipynb(nb_file)

And calling this file (ipynb2Rmd.R) as:

Rscript  ipynb2Rmd.R

Will show that the output title is not their default. We then need to update the code to read other tags in the metadata.

@milanmlft
Copy link

This doesn't seem relevant anymore so closing.

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

No branches or pull requests

3 participants