coatless-rpkg / assignr

Tools for Educators Writing Assignments in RMarkdown
https://r-pkg.thecoatlessprofessor.com/assignr/
42 stars 7 forks source link

removed chunks add extra newlines in -assign.Rmd file #18

Open daviddalpiaz opened 2 years ago

daviddalpiaz commented 2 years ago

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

daviddalpiaz commented 2 years ago

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)
}