Initial Development Effort

Defining BdQuestion class.

BdQuestion <-
    setRefClass(
        "BdQuestion",
        fields = list(
            question = "character",
            possible.responses = "character",
            users.answer = "character",
            child.questions = "list",
            quality.checks = "list",
            question.type = "character"
        ),
        methods = list(
            initialize = function(question = NA,
                                  possible.responses = list(),
                                  child.questions = list(),
                                  quality.checks = list(),
                                  question.type = list()) {
                .self$question <- question
                .self$possible.responses <- possible.responses
                .self$child.questions <- child.questions
                .self$quality.checks <- quality.checks
                .self$question.type <- question.type
                .self$message()
            },
            
            printQuestion = function() {
                cat(.self$question, "\n")
                for (i in 1:length(.self$possible.responses)) {
                    cat(" ", i, " ", .self$possible.responses[i], "\n")
                }
                .self$getResponse()
            },
            
            getResponse = function() {
                ans <- readline()
                .self$users.answer <-
                    .self$possible.responses[as.numeric(ans)]
            },
            
            addQualityChecks = function(newChecks) {
                cat("Adding Quality Checks.")
                .self$quality.checks <-
                    c(.self$quality.checks, newChecks)
            },
            
            cleanData = function() {
                cat("Cleaning sequence initiated.")
            },
            
            addToReport = function() {
                cat("Adding to Report.")
            },
            
            message = function() {
                cat("New Question object created.")
            },
            
            printSelf = function() {
                print(.self$question)
                for (i in 1:length(.self$possible.responses)) {
                    cat(" ", i, " ", .self$possible.responses[i], "\n")
                }
                cat("\n")
            }
        )
    )

Defining BdQuestionContainer class.

BdQuestionContainer <-
    setRefClass(
        "BdQuestionContainer",
        fields = list(BdQuestions = "list"),
        methods = list(
            initialize = function(BdQuestions = NA) {
                "Construct an instance of sampleInfoCollectionClass after validating the type."
                
                if (class(BdQuestions[[1]]) != "BdQuestion") {
                    stop("Incompatible input type. Provide a list of BdQuestion")
                }
                .self$BdQuestions <- BdQuestions
                .self$message()
            },
            
            message = function() {
                cat(
                    "New BdQuestionContainer instance created with ",
                    length(.self$BdQuestions),
                    " questions."
                )
            },
            
            printSelf = function() {
                for (question in .self$BdQuestions) {
                    question$printSelf()
                }
            }
        )
    )

Periodical Development Effort

Creating / Expanding questionnaire

question1 <-
    BdQuestion(
        question = "What is the lowest taxonomic level you require in your data?",
        possible.responses = c("Sub Species", "Species", "Genus", "Family", "Kingdom"),
        question.type = "Atomic"
    )
## New Question object created.
question2 <-
    BdQuestion(
        question = "What you want to do with data with mismatched names?",
        possible.responses = c("Keep as it is", "Remove", "Try to fix"),
        question.type = "Atomic"
    )
## New Question object created.
question3 <-
    BdQuestion(
        question = "What is the spatial resolution required for your data? (in meteres)",
        possible.responses = "NA",
        question.type = "Atomic"
    )
## New Question object created.
question4 <-
    BdQuestion(
        question = "Do you care about dates of your observations?",
        possible.responses = c("Yes" , "No"),
        question.type = "Router"
    )
## New Question object created.
question5 <-
    BdQuestion(
        question = "What is the earliest date of your observations in this data set (YYYY-mm-dd)",
        possible.responses = "NA",
        question.type = "Atomic"
    )
## New Question object created.
question6 <-
    BdQuestion(
        question = "What temporal resolution are you interested in?",
        possible.responses = c("Year", "Month", "Day"),
        question.type = "Atomic"
    )
## New Question object created.
allQuestions <-
    BdQuestionContainer(c(
    question1,
    question2,
    question3,
    question4,
    question5,
    question6
    ))
## New BdQuestionContainer instance created with  6  questions.

Execution in Package

allQuestions$printSelf()
## [1] "What is the lowest taxonomic level you require in your data?"
##   1   Sub Species 
##   2   Species 
##   3   Genus 
##   4   Family 
##   5   Kingdom 
## 
## [1] "What you want to do with data with mismatched names?"
##   1   Keep as it is 
##   2   Remove 
##   3   Try to fix 
## 
## [1] "What is the spatial resolution required for your data? (in meteres)"
##   1   NA 
## 
## [1] "Do you care about dates of your observations?"
##   1   Yes 
##   2   No 
## 
## [1] "What is the earliest date of your observations in this data set (YYYY-mm-dd)"
##   1   NA 
## 
## [1] "What temporal resolution are you interested in?"
##   1   Year 
##   2   Month 
##   3   Day

Great! That’s all needed for a scalable and neat package. :)