Created
July 21, 2022 17:54
-
-
Save cromanpa94/bb0c0f4e0467b01136f99af838a5bd92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Make sure wkhtmltopdf is installed to the path... | |
#Set the working directory | |
mainDir <- getwd() | |
targetFiles <- list.files(pattern = "html", recursive = T, full.names = T) | |
dir.create("0_HTML") | |
targetFilesUpdated <- sub('/0_', "_", targetFiles, fixed = TRUE) | |
targetFilesUpdated <- sub('./', '0_HTML/', targetFilesUpdated) | |
file.rename(targetFiles, targetFilesUpdated) | |
##Get the PDFs | |
subDir <- paste0(mainDir, "/0_HTML") | |
setwd(subDir) | |
system('for f in *.html; do wkhtmltopdf "$f" "$f.pdf"; done') | |
setwd(mainDir) | |
##Export grades | |
targetFiles <- list.files(".", pattern = "README.md",recursive = TRUE, full.names = TRUE) | |
grades <- do.call(rbind,lapply(targetFiles, function(x){ | |
targetFile <- readLines(x) | |
points <- targetFile[grep("Auto-grade", targetFile)] | |
points <- gsub(".*,","",points) | |
points2 <- targetFile[grep("Extra credit", targetFile)] | |
points2 <- gsub(".*,","",points2) | |
points2 <- ifelse(length(points2) ==0 , NA, points2) | |
cbind.data.frame(student= strsplit(x, "/")[[1]][2] , points =points, points2=points2) | |
})) | |
##Export grades | |
write.csv(grades, "0_grades.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment