Skip to content

Commit

Permalink
fix doc rendering; simplify travis; check-in RStudio project
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Jun 13, 2017
1 parent 1711d64 commit bc7e306
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 84 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,7 +1,9 @@
.Rhistory
*.Rproj
.Rproj.user
.DS_Store

docs/*/*_cache

inst/examples/*/*
!inst/examples/*/*.R
!inst/examples/*/*.Rmd
17 changes: 17 additions & 0 deletions LDAvis.Rproj
@@ -0,0 +1,17 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
9 changes: 8 additions & 1 deletion Makefile
@@ -1,2 +1,9 @@
all: site

clean:
rm -r docs/*/vis
rm docs/*/*.html
rm docs/*/*.md

site:
cd docs && Rscript knit_examples.R && cd ..
cd docs && Rscript render.R && cd ..
16 changes: 3 additions & 13 deletions docs/AP/AP.html
Expand Up @@ -207,21 +207,11 @@ <h1>Associated Press</h1>

<pre><code class="r">library(&quot;LDAvis&quot;)
data(AP, package = &quot;LDAvisData&quot;)
json &lt;- with(AP, createJSON(phi, theta, doc.length, vocab, term.frequency))
serVis(json, out.dir = &#39;vis&#39;, open.browser = FALSE)
</code></pre>

<pre><code>## Error in find.package(package, lib.loc, verbose = verbose): there is no package called &#39;LDAvisData&#39;
</code></pre>

<pre><code class="r">json &lt;- with(AP, createJSON(phi, theta, doc.length, vocab, term.frequency))
</code></pre>

<pre><code>## Error in with(AP, createJSON(phi, theta, doc.length, vocab, term.frequency)): object &#39;AP&#39; not found
</code></pre>

<pre><code class="r">serVis(json, out.dir = &#39;vis&#39;, open.browser = FALSE)
</code></pre>

<pre><code>## Error in cat(json, file = file.path(out.dir, &quot;lda.json&quot;)): object &#39;json&#39; not found
<pre><code>## Loading required namespace: servr
</code></pre>

</body>
Expand Down
16 changes: 1 addition & 15 deletions docs/AP/AP.md
Expand Up @@ -7,24 +7,10 @@ Associated Press
```r
library("LDAvis")
data(AP, package = "LDAvisData")
```

```
## Error in find.package(package, lib.loc, verbose = verbose): there is no package called 'LDAvisData'
```

```r
json <- with(AP, createJSON(phi, theta, doc.length, vocab, term.frequency))
```

```
## Error in with(AP, createJSON(phi, theta, doc.length, vocab, term.frequency)): object 'AP' not found
```

```r
serVis(json, out.dir = 'vis', open.browser = FALSE)
```

```
## Error in cat(json, file = file.path(out.dir, "lda.json")): object 'json' not found
## Loading required namespace: servr
```
29 changes: 29 additions & 0 deletions docs/AP/vis/lda.json

Large diffs are not rendered by default.

17 changes: 2 additions & 15 deletions docs/Jeopardy/Jeopardy.html
Expand Up @@ -207,21 +207,8 @@ <h1>Jeopardy Data</h1>

<pre><code class="r">library(&quot;LDAvis&quot;)
data(Jeopardy, package = &quot;LDAvisData&quot;)
</code></pre>

<pre><code>## Error in find.package(package, lib.loc, verbose = verbose): there is no package called &#39;LDAvisData&#39;
</code></pre>

<pre><code class="r">json &lt;- with(Jeopardy, createJSON(phi, theta, doc.length, vocab, term.frequency))
</code></pre>

<pre><code>## Error in with(Jeopardy, createJSON(phi, theta, doc.length, vocab, term.frequency)): object &#39;Jeopardy&#39; not found
</code></pre>

<pre><code class="r">serVis(json, out.dir = &#39;vis&#39;, open.browser = FALSE)
</code></pre>

<pre><code>## Error in cat(json, file = file.path(out.dir, &quot;lda.json&quot;)): object &#39;json&#39; not found
json &lt;- with(Jeopardy, createJSON(phi, theta, doc.length, vocab, term.frequency))
serVis(json, out.dir = &#39;vis&#39;, open.browser = FALSE)
</code></pre>

</body>
Expand Down
18 changes: 0 additions & 18 deletions docs/Jeopardy/Jeopardy.md
Expand Up @@ -7,24 +7,6 @@ Jeopardy Data
```r
library("LDAvis")
data(Jeopardy, package = "LDAvisData")
```

```
## Error in find.package(package, lib.loc, verbose = verbose): there is no package called 'LDAvisData'
```

```r
json <- with(Jeopardy, createJSON(phi, theta, doc.length, vocab, term.frequency))
```

```
## Error in with(Jeopardy, createJSON(phi, theta, doc.length, vocab, term.frequency)): object 'Jeopardy' not found
```

```r
serVis(json, out.dir = 'vis', open.browser = FALSE)
```

```
## Error in cat(json, file = file.path(out.dir, "lda.json")): object 'json' not found
```
29 changes: 29 additions & 0 deletions docs/Jeopardy/vis/lda.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/knit_examples.R → docs/render.R
Expand Up @@ -7,7 +7,7 @@ knit_examples <- function() {
# navigate intp each example and knit individually
for (i in dirs) {
setwd(i)
e <- try(knitr::knit2html(input = paste0(i, ".Rmd"), envir = new.env()))
knitr::knit2html(input = paste0(i, ".Rmd"), envir = new.env())
setwd(old)
}
}
Expand Down
9 changes: 0 additions & 9 deletions docs/reviews/reviews.html
Expand Up @@ -304,9 +304,6 @@ <h3>Visualizing the fitted model with LDAvis</h3>

<p>Now we&#39;re ready to call the <code>createJSON()</code> function in <strong>LDAvis</strong>. This function will return a character string representing a JSON object used to populate the visualization. The <code>createJSON()</code> function computes topic frequencies, inter-topic distances, and projects topics onto a two-dimensional plane to represent their similarity to each other. It also loops through a grid of values of a tuning parameter, \(0 \leq \lambda \leq 1\), that controls how the terms are ranked for each topic, where terms are listed in decreasing of <em>relevance</em>, where the relevance of term \(w\) to topic \(t\) is defined as \(\lambda \times p(w \mid t) + (1 - \lambda) \times p(w \mid t)/p(w)\). Values of \(\lambda\) near 1 give high relevance rankings to <em>frequent</em> terms within a given topic, whereas values of \(\lambda\) near zero give high relevance rankings to <em>exclusive</em> terms within a topic. The set of all terms which are ranked among the top-<code>R</code> most relevant terms for each topic are pre-computed by the <code>createJSON()</code> function and sent to the browser to be interactively visualized using D3 as part of the JSON object.</p>

<pre><code>## Error in find.package(package, lib.loc, verbose = verbose): there is no package called &#39;LDAvisData&#39;
</code></pre>

<pre><code class="r">library(LDAvis)

# create the JSON object to feed the visualization:
Expand All @@ -317,17 +314,11 @@ <h3>Visualizing the fitted model with LDAvis</h3>
term.frequency = MovieReviews$term.frequency)
</code></pre>

<pre><code>## Error in createJSON(phi = MovieReviews$phi, theta = MovieReviews$theta, : object &#39;MovieReviews&#39; not found
</code></pre>

<p>The <code>serVis()</code> function can take <code>json</code> and serve the result in a variety of ways. Here we&#39;ll write <code>json</code> to a file within the &#39;vis&#39; directory (along with other HTML and JavaScript required to render the page). You can see the result <a href="http://cpsievert.github.io/LDAvis/reviews/vis">here</a>.</p>

<pre><code class="r">serVis(json, out.dir = &#39;vis&#39;, open.browser = FALSE)
</code></pre>

<pre><code>## Error in cat(json, file = file.path(out.dir, &quot;lda.json&quot;)): object &#39;json&#39; not found
</code></pre>

<p>If you discover something interesting in your data using <strong>LDAvis</strong>, you can share the result via a URL since the state of the visualization is stored in the URL at all times. For example, in the movie review data, you can quickly see that Topic 7 is broadly about comedies by linking directly to the state of LDAvis where the selected Topic is &ldquo;7&rdquo; and the value of \(\lambda\) is 0.6 with the following URL:</p>

<p><a href="http://cpsievert.github.io/LDAvis/reviews/vis/#topic=7&amp;lambda=0.6&amp;term=">http://cpsievert.github.io/LDAvis/reviews/vis/#topic=7&amp;lambda=0.6&amp;term=</a></p>
Expand Down
11 changes: 0 additions & 11 deletions docs/reviews/reviews.md
Expand Up @@ -114,9 +114,6 @@ MovieReviews <- list(phi = phi,
Now we're ready to call the `createJSON()` function in **LDAvis**. This function will return a character string representing a JSON object used to populate the visualization. The `createJSON()` function computes topic frequencies, inter-topic distances, and projects topics onto a two-dimensional plane to represent their similarity to each other. It also loops through a grid of values of a tuning parameter, $0 \leq \lambda \leq 1$, that controls how the terms are ranked for each topic, where terms are listed in decreasing of *relevance*, where the relevance of term $w$ to topic $t$ is defined as $\lambda \times p(w \mid t) + (1 - \lambda) \times p(w \mid t)/p(w)$. Values of $\lambda$ near 1 give high relevance rankings to *frequent* terms within a given topic, whereas values of $\lambda$ near zero give high relevance rankings to *exclusive* terms within a topic. The set of all terms which are ranked among the top-`R` most relevant terms for each topic are pre-computed by the `createJSON()` function and sent to the browser to be interactively visualized using D3 as part of the JSON object.


```
## Error in find.package(package, lib.loc, verbose = verbose): there is no package called 'LDAvisData'
```


```r
Expand All @@ -130,21 +127,13 @@ json <- createJSON(phi = MovieReviews$phi,
term.frequency = MovieReviews$term.frequency)
```

```
## Error in createJSON(phi = MovieReviews$phi, theta = MovieReviews$theta, : object 'MovieReviews' not found
```

The `serVis()` function can take `json` and serve the result in a variety of ways. Here we'll write `json` to a file within the 'vis' directory (along with other HTML and JavaScript required to render the page). You can see the result [here](http://cpsievert.github.io/LDAvis/reviews/vis).


```r
serVis(json, out.dir = 'vis', open.browser = FALSE)
```

```
## Error in cat(json, file = file.path(out.dir, "lda.json")): object 'json' not found
```

If you discover something interesting in your data using **LDAvis**, you can share the result via a URL since the state of the visualization is stored in the URL at all times. For example, in the movie review data, you can quickly see that Topic 7 is broadly about comedies by linking directly to the state of LDAvis where the selected Topic is "7" and the value of $\lambda$ is 0.6 with the following URL:

[http://cpsievert.github.io/LDAvis/reviews/vis/#topic=7&lambda=0.6&term=](http://cpsievert.github.io/LDAvis/reviews/vis/#topic=7&lambda=0.6&term=)
Expand Down

3 comments on commit bc7e306

@tuzfanfan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LDAvis helps me a lot! but i get in trouble when i run the last step:
serVis(json, out.dir = 'vis', open.browser = FALSE)
_20180523142634
it is a messy code! i guess the reason that my data is chinese but i dont know how to deal with this problem

@cpsievert
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tuzfanfan do you get the same result with the current CRAN version 0.3.2?

@tuzfanfan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpsievert yes,i got it. and i need to convert data code to 'UTF-8' otherwise it will be mess.i think the problem is that the default code in Chinese is 'GBK2312'

Please sign in to comment.