Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow non-R solution code #290

Merged
merged 8 commits into from
Mar 2, 2022
Merged

Allow non-R solution code #290

merged 8 commits into from
Mar 2, 2022

Conversation

gadenbuie
Copy link
Member

  • Don't try to parse non-R solution code
  • .solution isn't available in these cases
  • Update mock_this_exercise() to follow same flow

* Don't try to parse non-R solution code
* .solution isn't available in these cases
* Update mock_this_exercise() to follow same flow
@@ -169,7 +169,7 @@ check_exercise <- function(
)

# Skip parse checking if it was already done in {learnr}
if (!learnr_includes_parse_check(stage)) {
if (!learnr_includes_parse_check(stage) && identical(learnr_args$engine %||% "r", "r")) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, I'll think we'll want to standardize how we discover what language a piece of code is, but this is fine for now

Comment on lines +274 to +275
engine <- knitr_engine_caption(learnr_args[["engine"]])
if (!identical(engine, "R")) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I'd rather have a separate function or pattern to check for the exercise/code language, but I think that's a larger amount of work we'll want to tackle later on

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question: why does engine == "R", but learnr_args$engine == "r"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's totally one of the reasons to standardize. knitr_engine_caption() turns engine strings like r, sql, javascript into text suitable for the exercise caption, e.g. R, SQL or JavaScript. So "r" or NULL comes out as "R".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(In this case we're prepping the string for use in the message, so it makes sense to compare with "R".)

@@ -81,11 +85,11 @@ mock_this_exercise <- function(
.label = "mock",
.engine = "r",
.stage = "check",
.result = rlang::missing_arg(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between .result = rlang::missing_arg() and just .result with no default value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If .result isn't provided, we want to create .result from the .user_code, provided that it's R code that we can evaluate.

If we don't have R code though, we need the user to tell us what the result will be. That result might be NULL, so I'm using rlang::missing_arg() to tell the difference.

We could leave .result without a default value and use missing(.result) to catch that, but I prefer being explicit. I also prefer using "no default value" as a strong "required argument" signal; in this case .result isn't required.

Copy link
Contributor

@rossellhayes rossellhayes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@gadenbuie gadenbuie merged commit ac50318 into main Mar 2, 2022
@gadenbuie gadenbuie deleted the parse-check-r-only branch March 2, 2022 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants