Skip to content

Strange behaviour with attach() in preExec #65

@ShimantoRahman

Description

@ShimantoRahman

In the exercises for Statistical Modeling and Data Mining when data is loaded in, we tend to also attach the dataframe. Students can choose whether they use the traditional syntax of refering to columns df$col or use the attached names directly col. Today, when testing several exercises we came across an issue which we had not encountered previously. When a dataframe is attached in the preExec argument, if a column is called via traditional syntax and in the context uses the attached syntax, the dodona environment throws errors that this column cannot be found.

An example of this issue can be found in the exercise Logistic Regression 9 (code repository).
In this exercise the Smarket dataframe is loaded and attached from the ISLR package. One of the columns in this dataframe is Year, which contains integer values according to the year that the observations was recorded. One part of the exercise is creating a boolean vector "train" where the values are true if the year was before 2005.

If this code is ran:

train = Year < 2005

no issues are found, but if we attempt to use the traditional syntax:

train = Smarket$Year < 2005

Dodona throws the compilation error: "Error while evaluating context: object 'Year' not found".

This is the code in the preExec argument:

library(ISLR)
data(Smarket)
attach(Smarket)

This is the code that is ran in the context, before any tests are evaluated:

train = (Year < 2005)

glm.fit = glm(Direction ~ Lag1 + Lag2 + Lag3 + Lag4 + Lag5 + Volume,
                      data = Smarket, family = binomial, subset = train)

This issue also occurs in other exercises with different dataframes, loaded in from different packages.

Other examples:

I am unsure what exactly causes this behaviour, since both syntax should behave the same way. The last time I worked with the dodona platform and R judge (first week of february) this issue did not occur.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions