Skip to content

How can I use tidy.js with rmarkdown? #4

Answered by pbeshai
pbeshai asked this question in Q&A
Discussion options

You must be logged in to vote

switching to answer format

As shown on twitter, this can be done this way or via @gadenbuie's new tidyjs-r package.

---
title: "Untitled"
output: html_document
---

<script src="https://d3js.org/d3-array.v2.min.js"></script>
<script src="https://www.unpkg.com/@tidyjs/tidy/dist/umd/tidy.min.js"></script>

```{js}
// everything is available under the Tidy namespace
const { tidy, mutate, arrange, desc } = Tidy;

const data = [
  { a: 1, b: 10 }, 
  { a: 3, b: 12 }, 
  { a: 2, b: 10 }
]

const results = tidy(
  data, 
  mutate({ ab: d => d.a * d.b }),
  arrange(desc('ab'))
)
```

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

pbeshai
Feb 5, 2021
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by pbeshai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants