R-Guru Smile design: how to one in SIlhouette Studio ยป Smart Silhouette Resource Hub

Since debugging R programs is a challenge, it is best practices to test units and each R syntax update instead of building a complex expression first. Up to 80% of R debugging may be due to invalid syntax, missing or invalid R objects.  In addition, it is ideal to copy and update a working R code example instead of writing R code from scratch if possible.  For debugging %>% R piping code, it is best to test each component first and then to combine them.  Interpreting R error messages can be confusing. 

Need help with R functions, ex. lm() syntax: help(lm), help("lm"), ?lm, ?"lm"

Below are common errors and potential solutions.  It is best to test one statement at a time.

  • Typos, Capitalization and Mis-spelling
    • If you see “unexpected symbol”, check for missing commas
  • Packages, Libraries Are Not Loaded
    • Could not find function "x"...
    • This likely means that you typed the function name incorrectly, or forgot to install or load a package.
  • Objects
    • Object 'x' not found
  • This means that an object you are referencing does not exist. Perhaps code above did not run properly?
  • Function Syntax: Closing & Continuing Punctuation
  • Logic
    • Error in if
    • This likely means an if statement was applied to something that was not TRUE or FALSE.
  • Factors
  • Plotting
    • Error: Insufficient values in manual scale. 3 needed but only 2 provided. ggplot()
  • R Markdown 



Invalid or Missing Packages, Path names, Libraries not Loaded

Load and confirm packages, path names and libraries

Invalid or Missing Data Frames, Objects or Variables

Confirm correct and existing data frames (instead of matrix), objects and vars, lower case all names since case-sensitive, correct order of tasks (select, filter, etc.) within DPLYR (SQL) functions, apply group_by() before summary functions to prevent overall summaries

Invalid or Missing Functions or Operations

Confirm functions exist and correctly applied, confirm variable and function types are consistent

Invalid or Missing Parameters and Options

Confirm correct function usage, case-sensitive, cut/paste working example

Invalid or Missing Data or Format

Confirm data import is correct, lower case data since case-sensitive, remove extra spaces before and after data values, confirm correct date format, apply factors to assign invalid data as NA, data by descriptive stats, freq counts, min, max, etc.

Invalid Logic

Confirm process logic flow, test and view inputs and outputs of each function

Subscript out of Bounds

Confirm correct starting, ending and incrementing values, apply dim() to check # of rows and columns

NA or Missing Values

Confirm NA and missing values, convert NA to missing values, confirm joins and appends, apply ignore missing values parameter options

Incorrect Variable Types

Apply conversion functions to convert to character, numeric or dates before using in functions, confirm correct date format

Incorrect Symbols

Apply correct symbols: Assignment (<-), Direct Row and Column Reference ([]), Operators (==, &, |, !), Piping (output of first function %>% is input to second function)

Unbalanced Quotes, Parentheses

Confirm balanced quotes (‘) and parentheses , [], ()

Invalid Custom Functions

Confirm correct function structure syntax, parameters and collection of R functions, test using simple data frames, variables and values 

Powered by Wild Apricot Membership Software