datacamp-light icon indicating copy to clipboard operation
datacamp-light copied to clipboard

solution environment generating runtime error

Open maryctucker opened this issue 6 years ago • 1 comments

Hi, I wrote an exercise with the code below that is generating an error. The error goes away when I remove supernova(zHeight.model) from the solution environment. Do you know why this is happening? Any help would be much appreciated!

        <code data-type="pre-exercise-code">                
            require(mosaic)
            require(supernova)
            Fingers <- supernova::Fingers
            Fingers$zThumb <- zscore(Fingers$Thumb) 
            Fingers$zHeight <- zscore(Fingers$Height)
            Height.model <- lm(Thumb ~ Height, data = Fingers)
            zHeight.model <- lm(zThumb ~ zHeight, data = Fingers)
        </code>
        <code data-type="sample-code">
            # this quantifies error from Height.model 
            supernova(Height.model)
            
            # modify this to quantify error from zHeight.model
            supernova() 

        </code>
        <code data-type="solution">
            # this quantifies error from Height.model 
            supernova(Height.model)
            
            # modify this to quantify error from zHeight.model
            supernova(zHeight.model) 

        </code>
        <code data-type="sct">
            ex() %>% check_function("supernova", index = 1) %>% check_result() %>% check_equal() 
            ex() %>% check_function("supernova", index = 2) %>% check_result() %>% check_equal() 

And the error it throws: screen shot 2019-01-12 at 12 17 16 pm

maryctucker avatar Jan 12 '19 20:01 maryctucker

Here is a minimal reproducible example of the error:

Code:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Chapter 8 Exercise 12</title>
<script async src="https://cdn.datacamp.com/dcl-react-dev.js.gz"></script>
    </head>
    <body>
        <div data-datacamp-exercise data-lang="r" data-show-run-button = TRUE>
            <code data-type="pre-exercise-code">
                require(supernova)
                mtcars$new_col <- mtcars$mpg
            </code>
            <code data-type="solution">
                supernova(lm(new_col ~ hp, data = mtcars))
            </code>
        </div>
    </body>
</html>

Error message:

DataCamp encountered the following error during init: Error: Fail because of runtime error: object 'new_col' not found

Please try again, or refresh the page. Sorry for any inconvenience.

Notes:

  • The error will only occur when the lm() call is embedded within supernova() [e.g. supernova(lm(new_col ~ hp, data = mtcars))], but not when embedded in others [e.g. summary(lm(new_col ~ hp, data = mtcars))]
  • The error does not occur when the new variable is referenced explicitly like mtcars$new_col

adamblake avatar Jan 13 '19 23:01 adamblake