Git Product home page Git Product logo

litedown's Introduction

  ______  
 /   ⚡  \
/litedown\
\   ⚡    /
 \______/

R Markdown Reimagined

R-CMD-check CRAN release

This package provides a trimmed-down and reimagined implementation of R Markdown. It is much more lightweight, at the price of dropping some features. It does not depend on the R package knitr or the system package Pandoc.

Please consider this package experimental for now. The documentation is also very incomplete and still under development.

Markdown rendering

The function litedown::mark() is based on the R package commonmark, and renders Markdown to various output formats supported by commonmark, which are primarily HTML and LaTeX. MS Office formats are not supported.

Knitting

R Markdown documents need to be knitted to Markdown before being rendered to a target output format. The function litedown::fuse() plays a role similar to knitr::knit() and rmarkdown::render(). It fuses program code with narratives, i.e., it executes code in the source document and interweaves results with narratives in the output document.

Previewing

Try litedown::roam().

Scope

We want to limit the scope of this package. Most planned features have been implemented so far. Please feel free to file feature requests anyway, but we may be a little conservative when considering them (we will take votes into consideration, so please upvote features you like).

License

The litedown package is licensed under MIT.

litedown's People

Contributors

yihui avatar yutannihilation avatar

Stargazers

yibit avatar Santiago Mota avatar Sindri avatar Bobo Jamson avatar Matt Roumaya avatar Li Jian avatar Nathan Eastwood avatar Guozheng Huang avatar Cyrus Yip avatar Jan Gorecki avatar  avatar Camilo García avatar Bryan Woods avatar 刘思喆 avatar btklab avatar  avatar  avatar Hongtao Hao avatar Julian Tao avatar  avatar Tong Chen avatar 0x15 avatar Jimmy Briggs avatar Dan avatar Ingo Rohlfing avatar Gina Reynolds avatar Mārtiņš Liberts avatar W. Joel Schneider avatar  avatar Naomi Yudanin, PhD avatar  avatar Salim B avatar  avatar Ryan Harrison avatar Ashley Baldry avatar Brynjolfur Gauti Jónsson avatar Shitao Wu avatar  avatar Upalabdha avatar dai avatar Brent Kaplan avatar Aleksandar Tomašević avatar Zjardyn avatar Eyayaw Beze avatar Brancen Gregory avatar M. Edward (Ed) Borasky avatar Ronald Lencevičius avatar Julie Padilla avatar Andy Merlino avatar Zeki Akyol avatar Demian Grams avatar  avatar John Coene avatar Ayomide Akinwande avatar Lars Schöbitz avatar  avatar  avatar Tahir Enes Gedik avatar Dominik Böhler avatar Xinhui Liao avatar Vincent Arel-Bundock avatar Josh Allen  avatar Andrew Gene Brown avatar Emily Riederer avatar Mwavu avatar Jacob Scott avatar JohannesFriedrich avatar Tan Ho avatar TJ Mahr avatar Marc Bosch avatar Yongfu Liao avatar Andrew Allen Bruce avatar timelyportfolio avatar Francisco Rodriguez-Sanchez avatar Federico Marotta avatar Jason Moggridge avatar Nicola Rennie avatar Heather Turner avatar Simon Grund avatar Wenbo Lv avatar Johannes Breuer avatar Rodrigo Pires avatar Turgut avatar Allan Irvine avatar Jesus M. Castagnetto avatar François Michonneau avatar Bartosz Trochimowicz avatar Ryo Nakagawara avatar Nicolo' Foppa Pedretti avatar Nicholas Tierney avatar Henrik Bengtsson avatar Liang Zhang avatar  avatar Anatolii Tsyplenkov avatar  avatar Elian H. Thiele-Evans avatar Maximilian Mücke avatar Liripo avatar Charlie Gao avatar Till Krenz avatar

Watchers

 avatar timelyportfolio avatar  avatar Christophe Dervieux avatar Gina Reynolds avatar  avatar  avatar

litedown's Issues

CRAN release

Hi Yihui,
Thanks for working on this package. Do you have any estimates when it may be available on CRAN?
I would like to link it from my coming talk and CRAN link would be preferred.

建议:全新的世界,考虑使用全新的文件格式 .xmd

  1. yaml 里的关键词后面的冒号输入完毕后要是有一个下拉框菜单提示就好了,但是涉及的 .Rmd 文档,情况可能复杂点,如果是有一个全新的文档格式,没有了历史包袱,定义域会小很多,实现起来是不是就容易多了。
  2. 包名字改为 xdown.
  3. RStudio 里新建文档那里,From Template 里建议安排上 xdown 的席位。
  4. 帮助文档小品文里是否可以提供类似 quarto reference 这样的文档,自定义起来会轻松很多。
  5. 作为传递信息的介质,需且仅需一个。输出格式里建议有且仅有 html 即可,没必要支持其它格式,html 打印出来就是 PDF,如此以来,output 后面的选项是不是就极大的简化了,article、book、slider、blog、thesis、letter、card。嗯,我一直没有忘记 pagedown

渲染文档时产生的提示信息输出不是很美观

文档源码

---
output:
  litedown::html_format:
    options:
      toc: true
      number_sections: true
      embed_resources: false
    meta:
      css: ["default", "@heading-anchor"]
      js: ["@heading-anchor"]
---

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

重现过程

直接点击 Knit 按钮。

提示信息

202405300156

系统信息

xfun::session_info("litedown")
#> R version 4.2.3 (2023-03-15 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19045)
#> 
#> Locale:
#>   LC_COLLATE=Chinese (Simplified)_China.utf8 
#>   LC_CTYPE=Chinese (Simplified)_China.utf8   
#>   LC_MONETARY=Chinese (Simplified)_China.utf8
#>   LC_NUMERIC=C                               
#>   LC_TIME=Chinese (Simplified)_China.utf8    
#> 
#> Package version:
#>   commonmark_1.9.1 graphics_4.2.3   grDevices_4.2.3  litedown_0.0.20 
#>   stats_4.2.3      tools_4.2.3      utils_4.2.3      xfun_0.44

Created on 2024-05-30 with reprex v2.1.0

Figures drawn with plot() break code chunks into pieces

I find this counter-intuitive. Not sure if it's intended?

Here's an example:

Code in main.Rmd:

```{r}
#### Data ####
set.seed(2023)
subj_idx = 1:30
gender = rep(1:2, each=15)
heights = c(160, 175)[gender] + rnorm(30, sd=15)

#### Plot ####
ylim = c( min(heights)-5, max(heights)+5 )
plot( 1, type="n", xlim=c(.5,30.5), ylim=ylim,
      xlab="Subject Index", ylab="Height (cm)" )
points(  1:15, heights[ 1:15], col=2, pch=19 )
points( 16:30, heights[16:30], col=4, pch=19 )
abline( v=15.5, col="grey", lty="dashed" )
mtext( c("Girls","Boys"), at=c(7,23), col=c(2,4), padj=-.5 )
```

Output in Markdown

litedown::fuse("main.Rmd", output="output.md")
``` {.r}
#### Data ####
set.seed(2023)
subj_idx = 1:30
gender = rep(1:2, each=15)
heights = c(160, 175)[gender] + rnorm(30, sd=15)

#### Plot ####
ylim = c( min(heights)-5, max(heights)+5 )
plot( 1, type="n", xlim=c(.5,30.5), ylim=ylim,
      xlab="Subject Index", ylab="Height (cm)" )
```
![](<index__files/chunk-2-1.svg>)

``` {.r}
points(  1:15, heights[ 1:15], col=2, pch=19 )
points( 16:30, heights[16:30], col=4, pch=19 )
abline( v=15.5, col="grey", lty="dashed" )
mtext( c("Girls","Boys"), at=c(7,23), col=c(2,4), padj=-.5 )
```

Output in HTML

litedown::fuse("main.Rmd", output="output.html")

image


Huge thanks for this awesome work!

Rmd yaml header ignores "subtitle"

Reporting, in case that was overlooked

---
title: nice title
subtitle: nice subtitle
author: nice author
output:
  litedown::html_format:
    meta:
      css: [default, snap]
      js: [snap]
---

if it is out of scope feel free to close

Embedded resources not being cleaned

Apologies if I'm misunderstanding but it doesn't seem like embedded images (not checked when other resources are embedded) are being cleaned from disk. Minimal reprex ...

dir.create(dir <- tempfile())
file_in  <- file.path(dir, "example.litedown")

text <- r"(---
output:
    litedown::html_format
---

```{r}
plot(1:10,1:10)
```)"

cat(text, file = file_in)
list.files(dir, recursive = TRUE)
#> [1] "example.litedown"
litedown::fuse(file_in)
list.files(dir, recursive = TRUE)
#> [1] "example__files/chunk-1-1.png" "example.html"                
#> [3] "example.litedown"

Hope this makes sense.

Wishlist: support for bibliographies

About ~3k packages on CRAN use a .bib file in their vignette and there are more that embed the bibliography created from BibTeX. Of course bibliographies would also be common for other articles and books. So it would be great to have support for bibliographies in litedown.

A litedown user could generate their own bibliography without using BibTeX or Pandoc. One way is to create an "Rstyle" bibliography from a .bibfile with the rbibutils package:

# create demo .bib file
txt <- "@Manual{R,
  title = {R: A Language and Environment for Statistical Computing},
  author = {{R Core Team}},
  organization = {R Foundation for Statistical Computing},
  address = {Vienna, Austria},
  year = {2024},
  url = {https://www.R-project.org/},
}
  
@Manual{Matrix,
  title = {Matrix: Sparse and Dense Matrix Classes and Methods},
  author = {Douglas Bates and Martin Maechler and Mikael Jagan},
  year = {2024},
  note = {R package version 1.7-0},
  url = {https://CRAN.R-project.org/package=Matrix},
}"
fileConn <- file("example.bib")
writeLines(txt, fileConn)
close(fileConn)

# convert .bib to R style
library(rbibutils)
bibConvert("example.bib", "bib.R", outformat = "Rstyle")
#> $infile
#> [1] "example.bib"
#> 
#> $outfile
#> [1] "bib.R"
#> 
#> $nref_in
#> [1] 2
#> 
#> $nref_out
#> [1] 2

Then use this R style bibliography to create citations and a bibliography using functions from base R (base, utils):

# create list of  bibentry objects
bib <- source("bib.R")$value

# equivalent of citet
cite("R, Matrix", bib, textual = TRUE)
#> [1] "R Core Team (2024); Bates, Maechler, and Jagan (2024)"

# equivalent of citep
cite("R, Matrix", bib)
#> [1] "(R Core Team 2024; Bates et al. 2024)"

# print bibliography ordered alphabetically
# uses plain text (markdown) style defined by bibstyle function
# will print whole bib, not just cited refs
sort(bib)
#> Bates D, Maechler M, Jagan M (2024). _Matrix: Sparse and Dense Matrix
#> Classes and Methods_. R package version 1.7-0,
#> <https://CRAN.R-project.org/package=Matrix>.
#> 
#> R Core Team (2024). _R: A Language and Environment for Statistical
#> Computing_. <https://www.R-project.org/>.

Maybe a litedown implementation could be based on this approach? Ideally from a user point of view it would be close to the rmarkdown approach (bib in YAML, @key or [@key] in text, automatically generate references at the end) so that old documents are easily converted. But a lighter version might just add some sugar to the above, e.g. Rstyle bib in YAML, citet and citep functions that automatically use this bibliography, generated bibliography of only cited references.

Mention fig.alt in the docs

I'm happy to see that fig.alt is supported by litedown, but there is no mention of it in the docs. Since this was not always possible with rmarkdown I think it is worth including in an example or mentioning explicitly somewhere.

Allow template to be passed via `meta` argument?

Would it be worth allowing a template to be passed via the meta argument of mark? I've not thought too hard about this, and you likely have good reason for the current implementation, but I wonder if this would be a nice intermediate step between the yaml header and the global option approaches.

General questions about litedown

Hello, I've been very interested to see that you're giving rmarkdown another look.
I've red the docs and I have some questions, please let me know if this is not the place to ask for questions.

You say

HTML widgets are not supported yet, but may be reimagined in the future with some minimal support.

At work we use exclusively widgets but because we never managed to find a way to load them lazily in the browser (hence loading the document was unusably slow) we started to do the following: we use webshot (or webshot2 but it's buggy) to create snapshots and we link the actual html widget file to the snapshot picture. This has been a game changer for us, can I assume this will work as well ?
Happy to hear if you have a better way to do this.
BTW we are actually deferring the saving the widget to html on another thread which speeds up the rendering a lot, I do not know if you expect to do things similar to this as well but this might be food for thoughts.

You say

By default, litedown produces bare minimal HTML output, but many features can be enabled by adding CSS/JS assets (see 4).

Having a pleasing output is pretty important and too raw of an output might deter people, will you be showing examples or how to reproduce something like the default rmarkdown output, I am thinking something with a collapsible TOC as well ?

You say

You can feel more confident with using the chunk option cache = TRUE in litedown than in knitr. The new cache system is more robust and intelligent.

No hooks at the moment.

This is what perplexed me the most, I never could make use of caching satisfyingly. As long as you work with medium size data (say a few million rows and a few columns) chunks that will load/update/save the data will always be too long to load. I went through to modify the rds format to swap to qs to improve the cache loading (binary format a and multi-thread reading) but that's just too slow.
For the exact same reason I never could use the preview efficiently, the total re-rendering being too slow.
My view is that the only right thing is to not do anything at all when the code has not moved, very much like what jupyter is doing. I believe most user will knit the document in session anyway so data will be there. I personally solved this by creating a hook that won't eval the chunk if the hash of the code chunk has not changed, but if there is no hook I'd be lost.
Do you have a nice way to provide a way to work "a la jupyter" (as far as caching/kniting is concerned) ?

Many thanks for your work I am using it everyday, to me being able to use R code in eval is still a killing feature that no other tool provides.

Feature request/Idea (litedown authoring in obsidian)

Hi @yihui your commented on a github discussion I had with the developer of the obsidian code execution plugin[twibiral/obsidian-execute-code/issues/325] made me think. Isn't Obsidian a GREAT fit for litedown authoring?Obsidian is 100% markdown focused, and mostly common mark compatible I think. If you'd tweak the existing code execution plugin to generate slightly more pleasing output in visual mode, and you make custom buttons to render any page to pdf/html (I made those work for Quarto, which was a hassle because quarto doesn't like .md, litedown would have a problem with .md to begin with), yo;'d have a fully featured "literate programming" authoring experience inside an amazing note taking app. This really almost instantly becomes the ultimate data sketchpad so to speak.

With positron looking more like an IDE and far less WYSIWYG "literate programming" than RStudio (visually..) there is space for a tool that abstracts away loads of the developer bells and niceties to fully centrist the "literate programming" note/document.

typo

... you can either set the path ...

The "or" is after a few lines:
... Alternatively, ...

litedown/docs/03-mark.Rmd

Lines 272 to 281 in 9f5c936

If you want to use a custom template file, you can either set the path in the
global option `litedown.FORMAT.template` (where `FORMAT` is the output format
name (`html` or `latex`), e.g., in `.Rprofile`:
``` r
options(litedown.html.template = 'path/to/my/template.html')
```
The global option will be applied to all documents to be converted by `mark()`.
Alternatively, you can pass a template path to the `template` argument of the

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.