I am typing up some results comparing various methods for importing unicode files in R. I read in a CSV file using dplyr::read_csv()
and utils::read.csv()
, then compare them using dplyr::setdiff()
. In fact, the two data files are different because the column names are read differently by the default options of the two methods. This causes an error to be written to the console. I know how to fix the error itself; that is not the issue. The three commands in the markdown file are
```{r read.csv message=FALSE, warning=FALSE, error=FALSE}
dplyr_read_csv <- read_csv("World Class.csv")
base_read_csv_T <- read.csv("World Class.csv")
setdiff(dplyr_read_csv, base_read_csv_T)
```
..which, when run as an R script result in:
> setdiff(dplyr_read_csv, base_read_csv_T)
Error in `setdiff()`:
! `x` and `y` are not compatible.
✖ Cols in `y` but not `x`: `height..in..`, `weight..lb..`, `height..cm..`,
`weight..kg..`, `中文..Simplified.`, `中文..Traditional.`, `English..GB.`,
`English..US.`, `Русский.язык`, `Tiê.ng.Viê.t`.
✖ Cols in `x` but not `y`: `height (in.)`, `weight (lb.)`, `height (cm.)`, `weight
(kg.)`, `中文 (Simplified)`, `中文 (Traditional)`, `English (GB)`, `English
(US)`, `Русский язык`, `Tiếng Việt`.
I would like for this error to show in the generated output.
When I put the code in the R markdown file, the file will not knit because of this thrown error. I have done the obvious things like putting error = FALSE
in the R chunk, but none of my efforts have worked.
You can find the data file (named World Class.csv
) and the R markdown file (read_world_classes.Rmd
) in my github repository. What should I do to include this chunk and its error in the markdown file?
(There is a regular R script read_world_classes.R
that I initially made to compare a bunch of other file types aside from CSV. That's what all the other files in the repository are).
CodePudding user response:
As @bs93 said above, the correct output is obtained by adding error=TRUE
to the r chunk:
```{r error=true}
<code goes here>
```