Skip to content

Commit

Permalink
202502202 - troubleshooting guide
Browse files Browse the repository at this point in the history
  • Loading branch information
jncaskey committed Feb 20, 2025
1 parent a4331be commit 95b0bed
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions R.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,42 @@ However, do make sure to save your `R` scripts before exiting Rstudio.
To troubleshoot `R` issues, be resourceful.
Try googling the error message or issue you are experiencing.
See [here](#questions) for a list of places you can pose `R`-related questions for help.

In addition, particular errors/warnings/issues are below:
In addition, particular errors/warnings/issues are included below:

## General Troubleshooting Tips

1. **Run code line-by-line to identify the source of the error**
- If you are using RStudio, a red line will often appear on the lefthand side of the screen to indicate the particular line(s) of code that result in an error
- It may be useful to clear your working environment in R before trying to diagnose an error to be sure that you are not experiencing any interference from existing objects in the environment
- Running code line-by-line is particularly useful because it allows you to inspect the data at each step of its processing
- Data issues are a commonly the culprit of code errors (see below)
1. **Check for typos**
- Are all brackets/parentheses/etc. closed?
- Does the object/variable that you are referring to exist? (*If the object does not exisit, you will likely get an error message indicating `[object name] not found`*)
- Has it been defined somewhere prior in the code?
- Does it depend on something else to be created?
- Is its name spelled correctly?
- Highlighting the object or variable in question and using `CTRL-F` to search for it is a good way to check these things
- Did you spell the function you want to use correctly?
- Do you have commas separating items within a list/function/etc.?
1. **Does your working environment have what it needs?**
- Are all necessary packages/libraries installed?
Do any require an update?
- Are all expected objects (dataframes, lists, environment variables, etc) present?
Are they correct?
1. **Investigate the structure of your data**
- Errors such as `non-numeric argument to binary operator` indicate that the function you are trying to use is expecting to recieve numeric data as an input but one or more of the inputs are not numeric
- The function `class(data$variable)` (replace "data" and "variable" with whatever you are trying to invesitgate) is useful for determining how R is interpreting your data.
Often, data that look like numbers can end up being stored as a character (text) variable.
This can be due to import/export processes or due to an issue with data entry.
- For example, when `00` is entered instead of `0` in a numeric field R is likely to interpret the variable as a character instead of a number when importing the data
- Check to make sure that all expected rows/columns are present and that they look the way you expect them to
- If your dataset has been created by joining/merging multiple dataframes, any duplicate columns not accounted for when joining may have a suffix appended to distinguish them (i.e., `variable.x` or `variable.y`)
- To resolve this, either call the appended variable in subsequent manipulations (`variable.x` instead of `variable`) or deal with the duplicated columns before/during the joining process (e.g., include duplicate columns in the `by` argument of joining function or remove the redundant column from one of the datasets to be joined)
- If you have been creating/computing variables in your dataset, ensure that they are being computed as expected
- Check for `NA` (missing) or `NaN` (not a number) values.
Such values may not be an issue or error in all cases, but if you are not expecting that as a result of your computations, this might suggest an issue with the code and/or data structure
- Check whether the computed values are reasonable

## Warning: `PACKAGENAME` package in `FILEPATH` library will not be updated

Expand Down

0 comments on commit 95b0bed

Please sign in to comment.