Closed thereseanders closed 5 years ago
Why is the temporary file needed for option B? Is it not possible to extract it out without the temporary file? I imagine not, but I'm not sure why off the top of my head.
The return of get_file()
is a character string with the raw file contents. rmarkdown::yaml_front_matter()
expects a .Rmd
file as input and can therefore not directly be called on the return of get_file()
.
Here is the code snipped implementing option B) in the current version of peer_collect_score()
:
feedback = purrr::safely(get_file)(repo, file)
if (succeeded(feedback)) {
tempf = tempfile(fileext = ".Rmd")
zz = file(tempf, "w")
cat(feedback[[1]], file = zz)
close(zz)
scores = rmarkdown::yaml_front_matter(tempf)$params
unlink(tempf)
} else {
usethis::ui_oops(
"Cannot locate file {usethis::ui_value(file)} on repo {usethis::ui_value(repo)}."
)
}
I don't think a tempfile is needed here - this delves a bit into the weirdness of files vs connections in R but I think something like
txt = ghclass::repo_get_file()
tc = textConnection(txt)
rmarkdown::yaml_front_matter(tc)
should work.
Oh thats a great solution and it works! Thank you.
There are at least two alternative approaches for collecting grades from the YAML of the standardized feedback forms. Both options below first use
get_file()
to retrieve the content of the.Rmd
via the Contents API:"---\ntitle: \"Reviewer feedback for HW1\"\noutput: github_document\nparams:\n q1_score: 5\n q2_score: 3\n q3_score: 3\n q4_score: 5\n q5_score: 10\n---\n\n\n## Feedback\n\n1. Place Question 1 text here.\n\nYour response goes here...\n\n2. Place Question 2 text here.\n\nYour response goes here...\n\n3. Place Question 3 text here.\n\nYour response goes here...\n\n4. Place Question 4 text here.\n\nYour response goes here...\n\n5. Place Question 5 text here.\n\nYour response goes here...\n"
One can extract the grades (i.e. 5, 3, 3, 5, 10) by:
A) Using string operations to extract the content of the grade tags from the raw content above.
OR
B) Using
tempfile()
to create a temporary.Rmd
file and then extract the information viarmarkdown::yaml_front_matter()
.Option B) seems preferable, because
rmarkdown::yaml_front_matter()
automatically outputs a list, but it also requires a potentially large number of temporary.Rmd
files, depending on the number of students and reviews.@mine-cetinkaya-rundel @rundel do you have any thoughts on which route to go with?