I wrote an article in .Rmd
using RStudio. When I complied it, I found there are lot of unwanted spaces between words. Is there a way to remove all of them at once?
Here is an example:
1.YAML
---
title: |
| **Chapter_3**
subtitle: |
| subtitle
author:
- Saneesh Cherapurath Soman$^1 , ^2$ newline
output:
pdf_document:
latex_engine: pdflatex
word_document: default
mainfont: "Times New Roman"
fontsize: 12pt
geometry: margin = 1in
number_sections: true
---
## Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse neque risus, interdum ac nunc non, tempus sollicitudin sapien. Suspendisse eget lectus a quam vehicula mollis **three spaces space end.** Integer eros est, tempus vulputate malesuada quis, tincidunt id augue. Donec sed mattis ante, sit amet ullamcorper quam **two spaces start space end.**
And I saved it, as Chapter_3.Rmd
Here is what I did:
Made a new r script, and in it:
corrected_text <- source('Chapter_3.Rmd')
gsub("\s+"," ", corrected_text)
But when I run this script, it shows errors like the following:
Error in source("test1.Rmd") : test1.Rmd:2:8: unexpected '|'
1: ---
2: title: |
^
or r thinks ^
, *
, |
as unexpected symbols.
In short, after writing the whole article I would like to run the script to remove additional space between words for the whole document, if possible on the same .Rmd
file.
Does anyone know how to solve this? Thanks in advance.