Add as.list() method for gradecode_found objects#49
Conversation
…y with S3 generic
|
What does this look like when there are multiple results in the user code? Also I'm realizing that what might be missing in this structure is something that describes the hierarchy of requests, e.g. functions → arguments → operators. |
|
@gadenbuie If there are multiple results, you get a character vector if library(gradecode)
as.list(find_arguments("mean(1:10, trim = 0.1, na.rm = TRUE)")) %>% str()
#> List of 1
#> $ :List of 3
#> ..$ type : chr "argument"
#> ..$ request: chr NA
#> ..$ result : chr [1:3] "1:10" "trim = 0.1" "na.rm = TRUE"Or a list if as.list(find_arguments("mean(1:10, trim = 0.1, na.rm = TRUE)"), as_xml = TRUE)
#> [[1]]
#> [[1]]$type
#> [1] "argument"
#>
#> [[1]]$request
#> [1] NA
#>
#> [[1]]$result
#> [[1]]$result[[1]]
#> {xml_nodeset (1)}
#> [1] <expr line1="1" col1="6" line2="1" col2="9" start="43" end="46">\n <expr ...
#>
#> [[1]]$result[[2]]
#> {xml_nodeset (3)}
#> [1] <SYMBOL_SUB line1="1" col1="12" line2="1" col2="15" start="49" end="52">t ...
#> [2] <EQ_SUB line1="1" col1="17" line2="1" col2="17" start="54" end="54">=</EQ ...
#> [3] <expr line1="1" col1="19" line2="1" col2="21" start="56" end="58">\n <NU ...
#>
#> [[1]]$result[[3]]
#> {xml_nodeset (3)}
#> [1] <SYMBOL_SUB line1="1" col1="24" line2="1" col2="28" start="61" end="65">n ...
#> [2] <EQ_SUB line1="1" col1="30" line2="1" col2="30" start="67" end="67">=</EQ ...
#> [3] <expr line1="1" col1="32" line2="1" col2="35" start="69" end="72">\n <NU ...Created on 2022-10-06 with reprex v2.0.2 In terms of showing the precedence, it's somewhat communicated by the order of the elements in the list. Can you see an elegant way to explicitly include it in the list? Adding an separate element kind of breaks the idea of each list element equals one |
|
How would something like this be handled? library(gradecode)
"mean(1:10, trim = 0.1, na.rm = TRUE)
median(na.rm = FALSE, 1:10)" %>%
find_functions() %>%
find_arguments() %>%
as.list() %>%
str() |
|
Oh okay, that'll take some work to get multiple expressions working! |
… in `$initialize()` This saves having to call `strsplit()` in multiple functions that deal with `$user_code`
|
@gadenbuie Multiple expressions are now supported. Right now, the results aren't separated into their respective expressions, but that that's true in library(gradecode)
"mean(1:10, trim = 0.1, na.rm = TRUE)
median(na.rm = FALSE, 1:10)" %>%
find_functions() %>%
find_arguments() %>%
as.list() %>%
str()
#> List of 2
#> $ :List of 3
#> ..$ type : chr "function"
#> ..$ request: chr NA
#> ..$ result : chr [1:2] "mean" "median"
#> $ :List of 3
#> ..$ type : chr "argument"
#> ..$ request: chr NA
#> ..$ result : chr [1:5] "1:10" "trim = 0.1" "na.rm = TRUE" "na.rm = FALSE" ...Created on 2022-10-11 with reprex v2.0.2 |
…nal `user_code` if `user_code` is XML instead of a string
By default, only show details of last result If `every_step = TRUE`, show all steps
…()` methods for `gradecode_found` objects
TODO
|
The `result` column must be a list column. List columns are only supported by tibbles, not data frames, so it doesn't make sense to have an `as.data.frame()` method
Use the
as_xmlargument to get$resultas XML instead of text.Created on 2022-10-06 with reprex v2.0.2
Closes #46.