Repository navigation
Closed
Description
I'm not sure if this is a bug with the way I am using reprex, but when I try to copy and paste this code two odd things occur:
- When I copy and paste the code onto github, it seems like there are slashes that are put into my column headers, which seems like a bug:
- Secondly, it seems like there is a bit of a spacing issue, which makes the table not renderable on github:
Code below:
#Sample Dataframe
pacman::p_load(magrittr,dplyr,formattable)
sample = data.frame(
beer_brewerId = c("8481", "8481", "8481"),
rev_app = c("4","1", "2"),
beer_name = c("John Harvards Simcoe IPA", "John Harvards Simcoe IPA", "John Harvards American Brown Ale"),
review_taste =c("6", "7", "6"), stringsAsFactors = FALSE
)
glimpse(sample)
formattable(sample, align ="c")
#Piping:
sample %>%
filter(beer_name == "John Harvards Simcoe IPA") %>%
formattable(., align = "c")
Output from reprex() function:
#Sample Dataframe
pacman::p_load(magrittr,dplyr,formattable)
sample = data.frame(
beer_brewerId = c("8481", "8481", "8481"),
rev_app = c("4","1", "2"),
beer_name = c("John Harvards Simcoe IPA", "John Harvards Simcoe IPA", "John Harvards American Brown Ale"),
review_taste =c("6", "7", "6"), stringsAsFactors = FALSE
)
glimpse(sample)
#> Observations: 3
#> Variables: 4
#> $ beer_brewerId <chr> "8481", "8481", "8481"
#> $ rev_app <chr> "4", "1", "2"
#> $ beer_name <chr> "John Harvards Simcoe IPA", "John Harvards Simco...
#> $ review_taste <chr> "6", "7", "6"
formattable(sample, align ="c")| beer\_brewerId | rev\_app | beer\_name | review\_taste |
|---|---|---|---|
| 8481 | 4 | John Harvards Simcoe IPA | 6 |
| 8481 | 1 | John Harvards Simcoe IPA | 7 |
| 8481 | 2 | John Harvards American Brown Ale | 6 |
#Piping:
sample %>%
filter(beer_name == "John Harvards Simcoe IPA") %>%
formattable(., align = "c")
<table class="table table-condensed">
<thead>
<tr>
<th style="text-align:center;">
beer\_brewerId
</th>
<th style="text-align:center;">
rev\_app
</th>
<th style="text-align:center;">
beer\_name
</th>
<th style="text-align:center;">
review\_taste
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center;">
8481
</td>
<td style="text-align:center;">
4
</td>
<td style="text-align:center;">
John Harvards Simcoe IPA
</td>
<td style="text-align:center;">
6
</td>
</tr>
<tr>
<td style="text-align:center;">
8481
</td>
<td style="text-align:center;">
1
</td>
<td style="text-align:center;">
John Harvards Simcoe IPA
</td>
<td style="text-align:center;">
7
</td>
</tr>
</tbody>
</table>
Metadata
Metadata
Assignees
Labels
No labels
Activity
pgensler commentedon Mar 31, 2017
I believe the reprex function is inserting an extra line break between the code and the HTML rendered. I have attached the screenshot with the tables having extra /'s in the HTML, and what code is throwing the error.


The correct output should be as such::
pgensler commentedon Mar 31, 2017
attaching rstudio viewerpane for verification:

hadley commentedon May 26, 2017
Could you please construct a simpler reprex? For your case this would include loading packages in a standard way, eliminating unneeded packages (magrittr + dplyr) and simplifying the data frame.
jennybc commentedon May 26, 2017
An important aspect of this is the HTML output of formattable, so the title is a bit misleading. If I save this reprex as
.Rwith this yaml:And render it with rmarkdown directly, the
.mdhas the same "features", e.g. the escaped underscores in the variable names and the lack of space between the html table and the next R chunk. Ditto if I store this code in.Rmd.So I think this is really about how
rmarkdown::render()works when output format isgithub_documentand a chunk creates html.jennybc commentedon Sep 27, 2017
I think I have the fix. With it, the original code (modified to not use pacman) produces this output:
beer_brewerId
rev_app
beer_name
review_taste
8481
4
John Harvards Simcoe IPA
6
8481
1
John Harvards Simcoe IPA
7
8481
2
John Harvards American Brown Ale
6
beer_brewerId
rev_app
beer_name
review_taste
8481
4
John Harvards Simcoe IPA
6
8481
1
John Harvards Simcoe IPA
7
Specify commonmark when venue = "gh"; fixes #77