data-8 / Gofer-Grader

Small autograding library
http://okgrade.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
16 stars 19 forks source link

Using okgrade with R in Jupyter #5

Open ttimbers opened 6 years ago

ttimbers commented 6 years ago

I would like to use okgrade with R in Jupyter - how I start to move forward on this and make this possible?

Some naive ideas I have started to play with include using reticulate (an R package that lets you call Python from R) to import okgrade and call the grade function. And then to use the rpy2 library to call R from Python for the tests in the .py files in tests directory. This seems like a hacky workaround which is less than ideal... Any help/ideas would be appreciated!

jkuruzovich commented 6 years ago

I'd love to be able to support some of our R users and I think R support would be a great enhancement. I have a little funding to hire one of our students and might give a shot.

I've been creating R tests with test_that.

#This will load the library.
library('testthat')
#This will generate a file with the output from the tests. You should be sure to test and submit the commit tests.md file.
sink("tests.md")
test_file("test.intro-r-exercises.R", reporter = "tap")
sink() 

The test file looks like this:

  test_that("Q1 Create a variable called sepal_width.mean", {
    expect_equal(sepal_width.mean, 3.054)
  })

  test_that("Q2Create a new column of iris.df called sepalArea", {
    expect_equal(mean(iris.df$sepal_area), 17.80653,tolerance=1e-3)
  })

  test_that("Q3 Create a new dataframe iristrain.df that includes the first 75 rows", {
    expect_equal(nrow(iristrain.df), 75)
    expect_equal(mean(iristrain.df$sepal_length), 5.341333,tolerance=1e-3)
  })

  test_that("Q4 Create a new dataframe iristest.df that includes the last 75 rows of the iris dataframe.", {
    expect_equal(nrow(iristest.df), 75)
    expect_equal(mean(iristest.df$sepal_length), 6.345333,tolerance=1e-3)
  })

  test_that("(5). Create a new vector sepal_length from the sepal_length column of the iris dataframe.", {
    expect_equal(mean(sepal_length), 5.843333,tolerance=1e-3)
    expect_equal(length(sepal_length), 150)
  })

I think if there were a standard way of specifying the tests (similar to R and Python) and a common output file structure, the system would be able to be somewhat agnostic between R and Python.