coatless-rpkg / assignr

Tools for Educators Writing Assignments in RMarkdown

Home Page:https://r-pkg.thecoatlessprofessor.com/assignr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

removed chunks add extra newlines in -assign.Rmd file

daviddalpiaz opened this issue · comments

Assignment R Markdown files created with assignr have one additional newline for each (solution) chunk removed.

I'm currently running the following on the -assign.Rmd files as a part of my build process for a course:

remove_extra_newlines = function(file) {
  input = readLines(file)
  output = which(input == "")
  output = input[-(output[which((output + 1)[-length(output)] == output[-1])])]
  output = output[-length(output)]
  writeLines(text = output, con = file)
}