Little useless-useful R functions – Useless interface for learning irregular verbs

[This article was first published on R – TomazTsql, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

So you want to train your knowledge on irregular verbs or your child is learning all forms of the verbs or you are getting prepared for post-covid travel a crash-course of grammar would not hurt.

Yes, this useless function will help you get back in shape.

Run the code train for brains and watch the results. The function is straightforward:

learnVerbs <- function() {

        #
        # populate the list of irregular verbs
        #
        df <- data.frame(verb=c( "alight","arise","awake")
                                  ,past=c("alighted","arose","awoke")
                                  ,past_perfect=c( "alighted","arisen","awoken")
        )
        
        # to exit the loop type: ex                
        exit <- "ex"
        correct <- 0
        wrong <- 0


        repeat {
          cat("\014")
          randomWord <- df[sample(nrow(df), 1), ]
          randomWord[1]
          formW <- sample(c("past","past_perfect"), 1)
          promptText <- paste0("Find the __", formW, "__ form for the verb >>", toupper(randomWord[1,1]),"<< : ")
          #promptText
          inputW <- toupper(readline(prompt=promptText))
          if (inputW == toupper(randomWord[1,formW])) {
            print("bravo")
            correct <- correct + 1
            barplot(table(as.character(c(replicate(correct, "correct"), replicate(wrong, "wrong")))), main = "correct vs. wrong", ylab="Number of words")
            randomWord <- ""
        
          } else {
            if (inputW == toupper(exit)){
              #wrong <- wrong -  1
              break
              #barplot(table(as.character(c(replicate(correct, "correct"), replicate(wrong, "wrong")))))
            } else {
            print("naaah")
            wrong <- wrong +  1
            barplot(table(as.character(c(replicate(correct, "correct"), replicate(wrong, "wrong")))), main = "correct vs. wrong", ylab="Number of words")
            randomWord <- ""
          }
        }
        }
}

and simply run the function:

# Run the function
learnVerbs()

In console pane enter the verb in asked form and get lucky.

and once you are super annoyed and fed up with this useless game, just type “ex” to exit the loop.

As always, code is available in at the Github in same Useless_R_function repository. The complete list of irregular verbs is also included on Github.

And not to mention, the function is language agnostic, which means that you can use it for german, Spanish or any other crazy language that have more than two tenses and gazillion of irregular verbs.

Happy R-coding!

To leave a comment for the author, please follow the link and comment on their blog: R – TomazTsql.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)