Undefined control sequence when using tufte-latex package - latex

I have a pandoc grid table in an otherwise brand-new bookdown project:
# Hello bookdown
All chapters start with a first-level heading followed by your chapter title, like the line above. There should be only one first-level heading (`#`) per .Rmd file.
+---------------+---------------+--------------------+
| Fruit | Price | Advantages |
+===============+===============+====================+
| Bananas | $1.34 | - built-in wrapper |
| | | - bright color |
+---------------+---------------+--------------------+
| Oranges | $2.10 | - cures scurvy |
| | | - tasty |
+---------------+---------------+--------------------+
Rendering to html and normal pdf via bookdown::gitbook and bookdown::pdf_book are fine, however rendering to a tufte format via tufte::tufte_book or bookdown::tufte_book2 fails with:
! Undefined control sequence.
<argument> #{} >{\raggedright \arraybackslash
}p{(\columnwidth - 4\tabcolsep...
l.93 ...umnwidth - 4\tabcolsep) * \real{0.29}}#{}}
The table structure is different to the other tables generated:
\begin{longtable}[]{#{}
>{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.22}}
>{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.22}}
>{\raggedright\arraybackslash}p{(\columnwidth - 4\tabcolsep) * \real{0.29}}#{}}
\toprule
Fruit & Price & Advantages \\
...
Therefore I think the source of the problem is in the tufte-latex package which tufte_book relies on, but I am unable to narrow it down further.
The tex code of the document is here - the culprit section starts at line 96.

This was an issue in the tufte package.
It has now been fixed in dev version 0.10.2 one can install from github
remotes::install_github("rstudio/tufte")
The fix will be on CRAN for next version 0.11

Related

How to get a static hardcoded table with number, caption and reference in Rmarkdown? [duplicate]

This question already has answers here:
Referencing a 'hand-made' table using bookdown package
(3 answers)
Closed last month.
I am trying to include a table in an Rmarkdown document, which is going to be rendered both in PDF and in HTML. I would like the table to float in the PDF version, and have a running number and a caption, and be linkable using \#ref.
Everything I have found in the interwebs is about how to produce a dynamic table based on some structure, using knitr and variants. I don't want that. I want a static, hardcoded table, and I have not been able to get this to work.
As an example, I have the following in my file tabletest.Rmd:
---
output: pdf_document
---
Lorem ipsum
| | Covered | Not covered |
| :---------- | :-------: | ------------: |
| Observed | $k$ | $n-k$ |
| Expected | $qn$ | $(1-q)n$ |
See Table X.
This is roughly the output I would like in PDF:
I created the desired output by LaTeXing a file with these contents:
\documentclass{article}
\begin{document}
Lorem ipsum
\begin{table}
\begin{tabular}{|c|c|c|}
& Covered & Not covered \\ \hline
Observed & $k$ & $n-k$ \\
Expected & $qn$ & $(1-q)n$
\end{tabular}
\caption{A table}\label{ref: table}
\end{table}
See Table \ref{ref: table}.
\end{document}
You have to use bookdown::pdf_document2, rather than (rmarkdown::)pdf_document, to use cross-references within a document, as explained in 4.7 Cross-referencing within documents of R Markdown Cookbook. You can make a cross-reference to a table by inserting (\#tab:label) to the table caption and by refering the table using \#ref(tab:label). See also the second paragraph from the last in 2.5 Tables of bookdown: Authoring Books and Technical Documents with R Markdown.
---
output:
bookdown::pdf_document2: default
---
Lorem ipsum
| | Covered | Not covered |
| :---------- | :-------: | ------------: |
| Observed | $k$ | $n-k$ |
| Expected | $qn$ | $(1-q)n$ |
Table: (\#tab:ref2tab-first) The caption for the first table
See Table \#ref(tab:ref2tab-first)
and compare it with Table \#ref(tab:ref2tab-second).
| | purchased | Not purchased |
| :---------- | :---------: | :-------------: |
| food | sausage | bread |
| book | bookdown | cookbook |
Table: (\#tab:ref2tab-second) The caption for the second table

How to replace space with space pipe and space?

I am writing documentation on GitHub. Tabular data needs to be represented on the Github page. For that one has to use pipe.
Below is the sample data:
SalesAgent SalesCountry SalesAmount
Tom UK 200
John US 180
John UK 260
David India 450
Tom India 350
This should be converted into tabular data that should be represented on Github page.
|SalesAgent|SalesCountry|SalesAmount|
|----------|------------|-----------|
|Tom |UK |200|
|John |US |180|
|John |UK |260|
|David |India |450|
|Tom |India |350|
The same process needs to done for several tables.
So one quick hack I thought of is to replace space with space pipe and space.
Tried replacing a space in atom and notepad++ editor. But it is not working.
How to do that using atom text editor. Please suggest, if there is any other text editor that does it more efficiently.
You can make use of Prettier to format GitHub Flavoured Markdown tables correctly. There are several ways to do so: CLI, web or using an Atom plugin (note that there are several others to choose from).
The following example uses the CLI version of Prettier, but the result should be the same with any other version.
$ cat example.md
|SalesAgent|SalesCountry|SalesAmount|
|----------|------------|-----------|
|Tom |UK |200|
|John |US |180|
|John |UK |260|
|David |India |450|
|Tom |India |350|
$ npx -q prettier example.md
| SalesAgent | SalesCountry | SalesAmount |
| ---------- | ------------ | ----------- |
| Tom | UK | 200 |
| John | US | 180 |
| John | UK | 260 |
| David | India | 450 |
| Tom | India | 350 |
Please note that I'm using npx to execute it once without installing. If you prefer, you can also install prettier globally and directly use prettier example.md.

How should browser and version be one hot encoded?

I need to output browser and version data for one hot encoding. We have come up with a few options (outlined below). I did some searching but couldn't find any existing examples of someone with similar data (searched Kaggle Datasets and DuckDuckGo).
Option 1: One column with browser name and version joined together
e.g. "browser_version" column values: "Safari-1.2.3", "Chrome-4.5.6", "Firefox-7.8.9"
| order_id | browser_version |
| 1 | Safari-1.2.3 |
| 2 | Chrome-4.5.6 |
| 3 | Firefox-7.8.9 |
Option 2: Two columns: one with browser name, another with browser version
e.g. "browser" (column 1) values: "Safari", "Chrome", "Firefox"
e.g. "version" (column 2) values: "1.2.3", "4.5.6", "7.8.9"
| order_id | browser | version |
| 1 | Safari | 1.2.3 |
| 2 | Chrome | 4.5.6 |
| 3 | Firefox | 7.8.9 |
Option 3: Two columns: one with browser name, another with browser name and version joined together
e.g. "browser" (column 1) values: "Safari", "Chrome", "Firefox"
e.g. "browser_version" (column 2) values: "Safari-1.2.3", "Chrome-4.5.6", "Firefox-7.8.9"
| order_id | browser | browser_version |
| 1 | Safari | Safari-1.2.3 |
| 2 | Chrome | Chrome-4.5.6 |
| 3 | Firefox | Firefox-7.8.9 |
What is the most beneficial way to set up the data values (assuming a CSV file, columns) for one hot encoding?
I suppose the correct answer might be to test each option and check the results but I thought this is likely is something that has been done before so I figured it's worth an ask.
I would use the first option. It will give on index per pair (browser | version).
The second option put version number of different browsers in the same column, whereas these numbers are not comparable. You can compare a Chrome version number with another Chrome version number but not a Chrome version number with a Firefox one.
And the third option contains the first one, with additional redundant data.

Specflow Feature-level Templates

I'm trying to execute an entire SpecFlow Feature using three different UserID/Password combinations. I'm struggling to find a way to do this in the .feature file without having to introduce any loops in the MSTest.
On the Scenario level I'm doing this:
Scenario Template: Verify the addition functionality
Given the value <x>
And the value <y>
When I add the values together
Then the result should be <z>
Examples:
|x|y|z|
|1|2|3|
|2|2|4|
|2|3|5|
Is there a way to do a similar table at the feature level that will cause the entire feature to be executed for each row in the table?
Is there other functionality available to do the same thing?
I don't think the snippet you have is working is it? I've updated the below with the corrections I think you need (as Fresh also points out) and a couple of possible improvements.
With this snippet, you'll see that the scenario is run for each line in the table of examples. So, the first test will connect with 'Bob' and 'password', ask your tool to add 1 and 2 and check that the answer is 3.
I've also added an ID column - that is optional but I find it much easier to read the results with an ID number.
Scenario Outline: Verify the addition functionality
Given I am connecting with <username> and <password>
When I add <x> and <y> together
Then the result should be <total>
Examples:
| ID | username | password | x | y | total |
| 1 | Bob | password | 1 | 2 | 3 |
| 2 | Helen | Hello123 | 1 | 2 | 3 |
| 3 | Dave | pa£sword | 1 | 2 | 3 |
| 4 | Bob | password | 2 | 3 | 5 |
| 5 | Helen | Hello123 | 2 | 3 | 5 |
| 6 | Dave | pa£sword | 2 | 3 | 5 |
| 7 | Bob | password | 2 | 2 | 4 |
| 8 | Helen | Hello123 | 2 | 2 | 4 |
| 9 | Dave | pa£sword | 2 | 2 | 4 |
"Is there a way to do a similar table at the feature level that will
cause the entire feature to be executed for each row in the table?"
No, Specflow (and indeed the Gherkin language) doesn't have a concept of a "Feature Outline" i.e. a way of specifying a collection of features which should be run in their entirety.
You could possibly achiever what you are looking for by making use of Specflow tags to tag related scenarios. You could then use your test runner to trigger the testing of all the scenarios with that tag e.g.
#related
Scenario: A
Given ...etc...
#related
Scenario: B
Given ...etc.
SpecFlow+ Runner (aka SpecRun, http://www.specflow.org/plus/), provides infrastructure (called test targets) to be able to run the same test suite (or selected scenarios) with different settings. With this you can solve problems like the one you have mentioned. It can be also used to run the same web tests with different browsers, etc. Check this screencast for details: http://www.youtube.com/watch?v=RZYV4Dvhw3w

Seeking HTML editor with visual tag matching

Is there an editor or IDE which will show HTML code with some visual indication of matching open/close tags?
Kompozer sort of helps, but I would prefer something like
.---><div>
|
| <h1>xxx</h1>
|
| .---><frameset>
| |
| | .---><div>
| | |
| | | <p>Lorem ipsum dolor sit amet</p>
| | |
| | .---></div>
| |
| .---></frameset>
|
.---></div>
which constantly updates as I write my code. The ability to fold inner tags would also be nice.
edit: any o/s, or cross-platform.
What operating system are you targetting?
I program mainly on Windows and I use Notepad++ for most text editing. It supports multiple languages, is fairly light weight and easy to install (has a zipped version which can be extracted to directory and run).
It supports syntax highlighting and code folding for HTML (via a tree/node structure on the left margin).
http://notepad-plus-plus.org/
hmm, for the record, MyEclipse HTML editor also looks very interesting ...
(source: myeclipseide.com)
oops, but it's not free :-(

Resources