Skip to content

Commit 95b0bed

Browse files
committed
202502202 - troubleshooting guide
1 parent a4331be commit 95b0bed

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

R.Rmd

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,42 @@ However, do make sure to save your `R` scripts before exiting Rstudio.
316316
To troubleshoot `R` issues, be resourceful.
317317
Try googling the error message or issue you are experiencing.
318318
See [here](#questions) for a list of places you can pose `R`-related questions for help.
319-
320-
In addition, particular errors/warnings/issues are below:
319+
In addition, particular errors/warnings/issues are included below:
320+
321+
## General Troubleshooting Tips
322+
323+
1. **Run code line-by-line to identify the source of the error**
324+
- 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
325+
- 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
326+
- Running code line-by-line is particularly useful because it allows you to inspect the data at each step of its processing
327+
- Data issues are a commonly the culprit of code errors (see below)
328+
1. **Check for typos**
329+
- Are all brackets/parentheses/etc. closed?
330+
- 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`*)
331+
- Has it been defined somewhere prior in the code?
332+
- Does it depend on something else to be created?
333+
- Is its name spelled correctly?
334+
- Highlighting the object or variable in question and using `CTRL-F` to search for it is a good way to check these things
335+
- Did you spell the function you want to use correctly?
336+
- Do you have commas separating items within a list/function/etc.?
337+
1. **Does your working environment have what it needs?**
338+
- Are all necessary packages/libraries installed?
339+
Do any require an update?
340+
- Are all expected objects (dataframes, lists, environment variables, etc) present?
341+
Are they correct?
342+
1. **Investigate the structure of your data**
343+
- 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
344+
- 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.
345+
Often, data that look like numbers can end up being stored as a character (text) variable.
346+
This can be due to import/export processes or due to an issue with data entry.
347+
- 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
348+
- Check to make sure that all expected rows/columns are present and that they look the way you expect them to
349+
- 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`)
350+
- 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)
351+
- If you have been creating/computing variables in your dataset, ensure that they are being computed as expected
352+
- Check for `NA` (missing) or `NaN` (not a number) values.
353+
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
354+
- Check whether the computed values are reasonable
321355

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

0 commit comments

Comments
 (0)