Coder Social home page Coder Social logo

rdym's Introduction

Rdym

  • Version: 0.4.0
  • Status: Build Status
  • License: License
  • Authors: Drew Schmidt and Homer White

Most search engines have a "did you mean?" feature, where suggestions are given in the presence of likely typos. And while search engines use sophisticated NLP methods on their vast amounts of user-generated data to create accurate suggestions, it turns out that you can get by with some ancient spellchecker techniques.

Example

Usage of the package is completely passive, beyond loading it with the usual library(Rdym) call. Say for example you run:

shapro.test(x=rnorm(20))
# Error: object 'shapro.test' not found

Note the missing "i" in what should be shapiro.test(). With Rdym loaded, you can get a "did you mean?" suggestion along with the error:

library(Rdym)

shapro.test(x=rnorm(20))
# Error: could not find function "shapro.test"
# 
# Did you mean:  shapiro.test()  ?
# shapiro.test(x=rnorm(20))

If the spellchecker guessed correctly, then you should be able to just copy/paste the suggestion after the "Did you mean" line into R.

Suggestions are given as errors are discovered by the R interpreter.
For example:

library(Rdym)

shapro.test(rmorm(20))
# Error: could not find function "shapro.test"
# 
# Did you mean:  shapiro.test  ?
# shapiro.test(rmorm(20))

shapiro.test(rmorm(20))
# Error in stopifnot(is.numeric(x)) : could not find function "rmorm"
# 
# Did you mean:  rnorm  ?
# shapiro.test(rnorm(20))

shapiro.test(rnorm(20))
#  Shapiro-Wilk normality test
# 
# data:  rnorm(20)
# W = 0.9366, p-value = 0.207

The package also has an explicit interface:

Rdym::RdymEnable()
nonsense
# Error: object 'nonsense' not found
# 
# Did you mean:  license  ?
# license 

Rdym::RdymDisable()
nonsense
# Error: object 'nonsense' not found

How it works

When R detects that a function or object listed in the user's input is not found, the package finds the minimum Levenshtein distance between the "unfound" token and all symbols in the user's global environment plus all loaded namespaces. The word with minimum Levenshtein distance (in the event of ties, the first such detected) is then suggested as an alternative to the missing symbol.

Fairly efficient C code is used to compute the Levenshtein distances. The "error interception" is just using R's options() to set a function to run post error (as seen here). The package won't work with batch mode R, so you have to use it in an interactive R session.

Also keep in mind this is basically just a toy. You shouldn't think of this as being in the same class of capabilities as a search engine's suggester.

Natural Language Support

We try to support all localizations available to R. For example:

Sys.setenv(LANGUAGE="de")
library(Rdym)
rmorm(10)
# Fehler: konnte Funktion "rmorm" nicht finden
# 
# Meinten Sie:  rnorm  ?
# rnorm(10) 

If your natural language is supported by R but does not work properly with Rdym, please file a report. In your report, please include how you are interfacing to R (e.g., RStudio, the terminal, R.app, ...) and the output of:

Sys.getenv("LANGUAGE")

All of the "did you mean?" localizations (found here) were probably generated by Google translate, and may not make any sense to a native speaker. If you have suggestions for improvement, please consider submitting a pull request or opening an issue.

Installation

You can install directly from GitHub via the devtools package:

devtools::install_github("wrathematics/Rdym")

rdym's People

Contributors

homerhanumat avatar wrathematics avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.