Skip to content

Commit

Permalink
Changed feedback file to be qarto document
Browse files Browse the repository at this point in the history
* Closes federicazoe#8
* Extenstions can now be: md, Rmd, qmd, html, pdf, docx
* Made render_feedback() to avoid redundancies/discrepancies between ends of core_assist_grading() and assist_regrading()
  • Loading branch information
CatalinaMedina committed Sep 27, 2023
1 parent 5d270f5 commit 947170e
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 133 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Imports:
fs,
utils,
svDialogs,
rmarkdown
quarto
Suggests:
knitr,
testthat (>= 3.0.0)
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import(dplyr)
import(fs)
import(ghclass)
import(readr)
import(rmarkdown)
import(rstudioapi)
import(stringr)
import(svDialogs)
importFrom(fs,file_create)
importFrom(fs,path_ext)
importFrom(fs,path_ext_set)
importFrom(quarto,quarto_render)
importFrom(readr,read_csv)
importFrom(readr,write_file)
importFrom(stringr,str_detect)
Expand Down
53 changes: 32 additions & 21 deletions R/assign_grade_write_feedback.R
Original file line number Diff line number Diff line change
Expand Up @@ -245,40 +245,51 @@ assign_grade_write_feedback <- function(
# Delete student's old feedback if it exists and write a new one
# This is important because the rubric could have changed
if(grading_progress_log_row$grading_status != "ungraded") {
unlink(grading_progress_log_row$feedback_path_Rmd)
unlink(grading_progress_log_row$feedback_path_to_be_knitted)
unlink(grading_progress_log_row$feedback_path_qmd)
unlink(grading_progress_log_row$feedback_path_to_be_rendered)

}

fs::file_create(grading_progress_log_row$feedback_path_Rmd)
fs::file_create(grading_progress_log_row$feedback_path_qmd)

# Determining type of file to knit feedback to
feedback_file_ext <- as.character(fs::path_ext(
grading_progress_log_row$feedback_path_to_be_knitted)[1]
grading_progress_log_row$feedback_path_to_be_rendered)[1]
)

feedback_knit_type <- case_when(
feedback_file_ext == "Rmd" ~ "html_document",
feedback_file_ext == "html" ~ "html_document",
feedback_file_ext == "docx" ~ "word_document",
feedback_file_ext == "pdf" ~ "pdf_document",
feedback_file_ext == "md" ~ "github_document",
TRUE ~ "NA",
)
if(feedback_file_ext == "qmd") {
feedback_file_ext <- "html"
}

# Create YAML section in feedback file
yaml <- paste(
"---",
'title: "Feedback"',
paste0('output: ', feedback_knit_type),
"---\n",
sep = "\n"
)
if (feedback_file_ext == "Rmd") {
grading_progress_log_row$feedback_path_qmd <- fs::path_ext_set(
grading_progress_log_row$feedback_path_qmd,
"Rmd"
)

yaml <- paste(
"---",
"title: 'Feedback'",
"output: html_document",
"---\n",
sep = "\n"
)

} else {
yaml <- paste(
"---",
"title: 'Feedback'",
paste0("format: ", feedback_file_ext),
"---\n",
sep = "\n"
)

}

# Write feedback in feedback file
readr::write_file(
x = paste0(yaml, "\n", feedback , "\n\n"),
file = grading_progress_log_row$feedback_path_Rmd,
file = grading_progress_log_row$feedback_path_qmd,
append = TRUE
)

Expand Down
4 changes: 2 additions & 2 deletions R/assist_grading-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#' @param example_feedback_path string; file path to one of the assignment feedback files that will be generated as the user grades.
#' This file path structure will be used to determine where the other feedback files will be stored.
#' The student identifier must be present somewhere in the file name and must be the only part of the file path unique to the student.
#' The extension of the feedback file must be one of the following: "Rmd", "md", "docx", "html", "pdf".
#' These file types (except the first) will be knitted to: GitHub, Word, html, and pdf documents respectively
#' The extension of the feedback file must be one of the following: "Rmd", "qmd", "md", "docx", "html", "pdf".
#' These file types (except the first two) will be knitted to: Markdown, Word, html, and pdf documents respectively
#' @param example_student_identifier string; a student identifier (e.g. name, id, id number, GitHub user name) that is used to identify the student on the roster.
#' This needs to be present somewhere in the example_assignment_path. The student_identifier needs to be the GitHub user name if the user wishes to push issues or feedback to GitHub later
#' @param example_team_identifier string; Used instead of example_student_identifier when grading team assignments with assist_team_grading().
Expand Down
58 changes: 12 additions & 46 deletions R/assist_regrading.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ assist_regrading <- function(
grading_progress_log <- readr::read_csv(
grading_progress_log_path,
show_col_types = FALSE,
col_types = cols(
col_types = readr::cols(
.default = readr::col_character(),
assignment_missing = readr::col_logical(),
grade_student = readr::col_logical(),
Expand All @@ -281,53 +281,19 @@ assist_regrading <- function(
team_grading = team_grading
)

feedback_file_ext <- fs::path_ext(
grading_progress_log$feedback_path_to_be_knitted[1]
)

# Let the user know that feedback is being knitted
cat(paste(
"\nTrying to knit feedback files to",
feedback_file_ext, "format...\n"
feedback_file_ext <- as.character(fs::path_ext(
grading_progress_log$feedback_path_to_be_rendered[1]
))

# Knit feedback
if (feedback_file_ext %in% c("docx", "html", "pdf", "md")) {
#Try to render feedback files
tryCatch(
# Specifying expression
expr = {
paths_returned <- mapply(
render,
grading_progress_log$feedback_path_Rmd[grading_progress_log$grading_status != "ungraded"],
MoreArgs = list(clean = TRUE, quiet = TRUE)
)

cat(paste("\n...Succeeded!\n\n"))

unlink(grading_progress_log$feedback_path_Rmd)

if (feedback_file_ext == "md") {
unlink(fs::path_ext_set(
path = grading_progress_log$feedback_path_Rmd,
ext = "html"
))

}

},

# Specifying error message
error = function(e){
cat(paste(
"There was an error when trying to render the feedback file in the specified format.",
"\nCompiling pdf's in R requires additional software.",
"We suggest you rerun the assist grading function with a different feedback_file_format.",
"All of your progressed will be saved in the grading progress log.",
sep = "\n"
))
}
)
if(!(feedback_file_ext %in% c("Rmd", "qmd"))) {
render_feedback_now <- svDialogs::dlg_message(
"Would you like the feedback files to be rendered now?",
type = "yesno"
)$res

if (render_feedback_now == "yes") {
render_feedback(grading_progress_log = grading_progress_log)
}
}

}
60 changes: 11 additions & 49 deletions R/core_assist_grading.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#' @import stringr
#' @import rstudioapi
#' @import svDialogs
#' @import rmarkdown
#' @import fs
#'
#' @keywords internal
Expand Down Expand Up @@ -71,8 +70,8 @@ core_assist_grading <- function(
# Check example_feedback_path is valid
feedback_file_ext <- fs::path_ext(example_feedback_path)

if (!(feedback_file_ext %in% c("Rmd", "docx", "html", "pdf", "md"))) {
stop("The extension of the example_feedback_path must be one of the following: '.Rmd', '.docx', '.html', '.pdf'.")
if (!(feedback_file_ext %in% c("md", "Rmd", "qmd", "html", "pdf", "docx"))) {
stop("The extension of the example_feedback_path must be one of the following: '.md', '.Rmd', '.qmd', '.html', '.pdf', '.docx'.")
} else if (!stringr::str_detect(example_feedback_path, example_student_identifier)) {
stop("The example_student_identifier must be present in the example_feedback_path file name.")
}
Expand Down Expand Up @@ -252,7 +251,7 @@ core_assist_grading <- function(
grading_progress_log <- readr::read_csv(
grading_progress_log_path,
show_col_types = FALSE,
col_types = cols(
col_types = readr::cols(
.default = readr::col_character(),
assignment_missing = readr::col_logical(),
grade_student = readr::col_logical(),
Expand All @@ -273,52 +272,15 @@ core_assist_grading <- function(
)
}

some_students_graded <- any(grading_progress_log$grading_status != "ungraded")

if (feedback_file_ext %in% c("docx", "html", "pdf", "md") && some_students_graded) {

# Let the user know that feedback is being knitted
cat(paste0(
"\nTrying to knit feedback files to ",
feedback_file_ext, " format...\n"
))

# Try to render feedback files
tryCatch(
# Specifying expression
expr = {
paths_returned <- mapply(
render,
grading_progress_log$feedback_path_Rmd[grading_progress_log$grading_status != "ungraded"],
MoreArgs = list(clean = TRUE, quiet = TRUE)
)

cat(paste("\n...Succeeded!\n\n"))

unlink(grading_progress_log$feedback_path_Rmd)

if (feedback_file_ext == "md") {
unlink(fs::path_ext_set(
path = grading_progress_log$feedback_path_Rmd,
ext = "html"
))

}

},

# Specifying error message
error = function(e){
cat(paste(
"There was an error when trying to render the feedback file in the specified format.",
"\nCompiling pdf's in R requires additional software.",
"We suggest you rerun the assist grading function with a different feedback_file_format.",
"All of your progressed will be saved in the grading progress log.",
sep = "\n"
))
}
)
if(!(feedback_file_ext %in% c("Rmd", "qmd"))) {
render_feedback_now <- svDialogs::dlg_message(
"Would you like the feedback files to be rendered now?",
type = "yesno"
)$res

if (render_feedback_now == "yes") {
render_feedback(grading_progress_log = grading_progress_log)
}
}

}
8 changes: 4 additions & 4 deletions R/create_grading_progress_log.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' @param github_issues logical, whether the grader wants to be given the option to create an issue in students' repos or not
#' @param team_grading logical, indicates if any assignment submission is associated with multiple students (e.g. team projects)
#'
#' @return tibble; with the columns read in from roster_path, including student_identifier, and two new columns, feedback_path_Rmd, feedback_path_to_be_knitted, and assignment_path containing the file paths to the student assignment files and student feedback files
#' @return tibble; with the columns read in from roster_path, including student_identifier, and two new columns, feedback_path_qmd, feedback_path_to_be_rendered, and assignment_path containing the file paths to the student assignment files and student feedback files
#'
#' @import stringr
#' @import dplyr
Expand Down Expand Up @@ -88,12 +88,12 @@ create_grading_progress_log <- function(

# Make feedback file paths, saved as .Rmd and the one to be knitted to
grading_progress_log_new <- grading_progress_log_new %>%
mutate(feedback_path_Rmd = stringr::str_replace_all(
as.character(fs::path_ext_set(example_feedback_path, ext = "Rmd")),
mutate(feedback_path_qmd = stringr::str_replace_all(
as.character(fs::path_ext_set(example_feedback_path, ext = "qmd")),
pattern = example_student_identifier,
replacement = grading_progress_log_new$student_identifier
)) %>%
mutate(feedback_path_to_be_knitted = stringr::str_replace_all(
mutate(feedback_path_to_be_rendered = stringr::str_replace_all(
as.character(example_feedback_path),
pattern = example_student_identifier,
replacement = grading_progress_log_new$student_identifier
Expand Down
4 changes: 2 additions & 2 deletions R/delete_student_grading_progress.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ delete_student_grading_progress <- function(
curr_row <- grading_progress_log[row_to_change, ]

# Delete old feedback file
unlink(curr_row$feedback_path_Rmd)
unlink(curr_row$feedback_path_qmd)
# Delete knitted feedback if present
unlink(curr_row$feedback_path_to_be_knitted)
unlink(curr_row$feedback_path_to_be_rendered)

# Set feedback_pushed = FALSE if column is present
if ("feedback_pushed" %in% colnames(curr_row)){
Expand Down
5 changes: 3 additions & 2 deletions R/globals.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ utils::globalVariables(c(
"student_identifier", # colname in grading_progress_log
"students_in_team", # colname in grading_progress_log
"grading_status", # colname in grading_progress_log
"feedback_info_updated", # colname in grading_progress_log
"feedback_codes", # colname in grading_progress_log
"graded_qs", # colname in grading_progress_log
"last_time_graded", # colname in grading_progress_log
Expand All @@ -15,8 +16,8 @@ utils::globalVariables(c(
"github_repo", # colname in grading_progress_log
"name", # colname in grading_progress_log
"team_identifier", # colname in grading_progress_log
"feedback_path_Rmd", # colname in grading_progress_log
"feedback_path_to_be_knitted", # colname in grading_progress_log
"feedback_path_qmd", # colname in grading_progress_log
"feedback_path_to_be_rendered", # colname in grading_progress_log
"assignment_path", # colname in grading_progress_log
"assignment_missing", # colname in grading_progress_log
"grade_student", # colname in grading_progress_log
Expand Down
65 changes: 65 additions & 0 deletions R/render_feedback.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#' Render feedback files for graded students
#'
#' @param grading_progress_log The grading progress log used internally by gradetools
#'
#' @importFrom fs path_ext_set
#' @importFrom quarto quarto_render
#'
#' @keywords internal
#'

render_feedback <- function(grading_progress_log){

feedback_file_ext <- as.character(fs::path_ext(
grading_progress_log$feedback_path_to_be_rendered[1]
))

ind_feedback_to_render <- grading_progress_log$grading_status != "ungraded"

if (any(ind_feedback_to_render)) {

# Let the user know that feedback is being knitted
cat(paste0(
"\nTrying to render feedback files to ",
feedback_file_ext, " format...\n"
))

# Try to render feedback files
tryCatch(
# Specifying expression
expr = {
paths_returned <- mapply(
quarto::quarto_render,
grading_progress_log$feedback_path_qmd[ind_feedback_to_render],
MoreArgs = list(quiet = TRUE)
)

cat(paste("\n...Succeeded!\n\n"))

unlink(grading_progress_log$feedback_path_qmd)

if (feedback_file_ext == "md") {
unlink(fs::path_ext_set(
path = grading_progress_log$feedback_path_qmd,
ext = "html"
))

}
},

# Specifying error message
error = function(e){
cat(paste(
"There was an error when trying to render the feedback file in the specified format.",
"\nCompiling pdf's in R requires additional software.",
"Feedback is rendered from a Quarto document (.qmd).",
"We suggest you rerun the assist grading function with a different feedback_file_format.",
"All of your progressed will be saved in the grading progress log.",
sep = "\n"
))
}
)

}

}
Loading

0 comments on commit 947170e

Please sign in to comment.