Since AssignmentCheck
is an R package, you should install R on your PC if you haven't already done so. To install the AssignmentCheck
package, run the following command at your R IDE, so you can also get the development version from GitHub:
install.packages("devtools") devtools::install_github("agricolamz/AssignmentCheck")
Load package:
library(AssignmentCheck)
Imagine that we have a directory with some files from our students
list.files()
my_files <- c("test_1.Rmd", "test_2.Rmd", "test_3.Rmd", "test_4.Rmd", "test.txt") my_files
As you can see, there are .Rmd
files and one .txt
file. These files have awfull names, but believe me: even if you ask your student to name files in line with some pattern, you will recieve a couple files with nasty names. Lets look inside of one of them:
readLines("test_1.Rmd")
my_files <- c( system.file("extdata", "test_1.Rmd", package = "AssignmentCheck"), system.file("extdata", "test_2.Rmd", package = "AssignmentCheck"), system.file("extdata", "test_3.Rmd", package = "AssignmentCheck"), system.file("extdata", "test_4.Rmd", package = "AssignmentCheck") ) readLines(my_files[1])
As a teacher you can make your own correct file and create an expectations object using make_expectations
function. Lets make test_1.Rmd
the base correct file:
make_expectations("test_1.Rmd")
make_expectations(my_files[1])
So that correct answers you can provide to the test_files
function. This function takes all .Rmd
files and check, whether R
code in R
chunks produces the same result that we expected. Our expectations should be provided via list()
object.
fit <- lm(mpg~cyl, mtcars) test_files(expectations = list(4, fit$coefficients))
fit <- lm(mpg~cyl, mtcars) show <- test_files(files = my_files, expectations = list(4, fit$coefficients)) show <- cbind.data.frame(show[,-5], file_name = c("test_1.Rmd", "test_2.Rmd", "test_3.Rmd", "test_4.Rmd")) show
As you can see, there are students' name from name:
field and summary for each student.
There is a variable keyword_prefix
that defines the common part of the keywords, so you can ask your students to put their answer code chunks after some keywords. By default keyword_prefix
is "### "
, so your students can write "### 1.1", "### 1.2" and so on. But you can specify your own prefixes.
If we combine both test_files
and make_expectations
functions we can get the same summary for all students:
test_files(expectations = make_expectations("test_1.Rmd"))
show <- test_files(files = my_files, expectations = make_expectations(my_files[1])) show <- cbind.data.frame(show[,-5], file_name = c("test_1.Rmd", "test_2.Rmd", "test_3.Rmd", "test_4.Rmd")) show
Sometimes it is nice to know the students' group, so just ask them to write "group: ..." (see readLines("test_1.Rmd")
example below) in the rmarkdown header and use group
argument.
test_files(expectations = make_expectations("test_1.Rmd", group = TRUE))
show <- test_files(files = my_files, expectations = make_expectations(my_files[1]), group = TRUE) show <- cbind.data.frame(show[,-6], file_name = c("test_1.Rmd", "test_2.Rmd", "test_3.Rmd", "test_4.Rmd")) show
It is important to note, that all checks don't create any variables in your working environment, so all students are checked independently. But you should know libraries that your students used and turn them on in advance.
If your students (and you) have some plots in your markdowns, they will be created in your Viewer, so it is nice practice to ask your students to write their names on the plots. There is no good way to check plot correctness, so I propose not to use automatic check here.
When you get the result metrix from the test_files()
function you can use the mistaken_tasks()
function for generating a new rmarkdown file with fragments of students' works.
result <- test_files(expectations = make_expectations("test_1.Rmd")) mistaken_tasks(result, write_file = FALSE)
show <- test_files(files = my_files, expectations = make_expectations(my_files[1])) mistaken_tasks(show, write_file = FALSE)
As you see, It is the new rmarkdown file, where all fragments with unexpected values are named after a student that produced this part of rmarkdown. If you use write_file = TRUE
it will creat a file "mistaken_tasks.Rmd"
in your working directory. You can open it using file.edit("mistaken_tasks.Rmd")
command.
AssignmentCheck
It is important to cite R and R packages when you use them. For this purpose use the citation
function in R:
citation("AssignmentCheck")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.