daranzolin / rcanvas

R Client for Canvas LMS API
Other
90 stars 43 forks source link

delete_wpage() fails with "object of type 'closure' is not subsettable" #40

Closed jonovik closed 5 years ago

jonovik commented 5 years ago

delete_wpage simply does not work.

> delete_wpage(123, "test-page")
Error in x[which(ind)] : object of type 'closure' is not subsettable

The problem is that delete_wpage() has no argument called args, yet tries to pass one to canvas_query:

delete_wpage <- function(course_id, page_url){
# DELETE /api/v1/courses/:course_id/pages/:url
url <- paste0(canvas_url(), file.path("courses", course_id, "pages", page_url))
resp <- canvas_query(url, args, "DELETE")

So base::args gets passed instead, which fails when canvas_query() tries to

args = sc(args)

The fix is to simply drop the unneeded args argument. However, the current canvas_query requires it:

function(urlx, args, type = "GET")

So if delete_wpage were to just call canvas_query(url, "DELETE"), "DELETE" would become the args argument, which is also a bug. Things seem to work if I set args = NULL as default in canvas_query.

(It would be nice to have unit tests for this, but it's tricky because that would require a test Canvas to be available.)