In addition to the good advice already given, I would add this:
It is probably best to avoid using require()
unless you actually will be using the value it returns e.g in some error checking loop such as given by thierry.
In most other cases it is better to use library()
, because this will give an error message at package loading time if the package is not available. require()
will just fail without an error if the package is not there. This is the best time to find out if the package needs to be installed (or perhaps doesn’t even exist because it it spelled wrong). Getting error feedback early and at the relevant time will avoid possible headaches with tracking down why later code fails when it attempts to use library routines
Related Posts:
- How to find out which package version is loaded in R?
- How to unload a package without restarting R
- Use of ~ (tilde) in R programming Language
- Counting the number of elements with the values of x in a vector
- How to remove outliers from a dataset
- dplyr: “Error in n(): function should not be called directly”
- Error in eval(expr, envir, enclos) : object not found
- How do I convert a factor into date format?
- Write lines of text to a file in R
- scale_fill_discrete and scale_fill_manual – legend options confusion
- ‘Incomplete final line’ warning when trying to read a .csv file into R
- Conditional mean statement
- Warning in GLM analysis
- What does ‘length of ‘dimnames’ [1] not equal to array extent’ mean?
- How do I flip rows and columns in R
- How to catch integer(0)?
- “no function to return from, jumping to top level”
- r random forest error – type of predictors in new data do not match
- env=baseenv() in R
- Sample random rows in dataframe
- Removing punctuations from text using R
- How to solve it. error:Error in data[[rowvar]] : attempt to select less than one element
- Gradient of n colors ranging from color 1 and color 2
- How to prevent scientific notation in R?
- How to declare a vector of zeros in R
- Replace all 0 values to NA
- R Sweave: NO TeX installation detected
- do-while loop in R
- ERROR: [on_request_read] connection reset by peer in R shiny
- Error in as.vector(x, mode) : cannot coerce type ‘closure’ to vector of type ‘any’
- Suppress output of a function
- Error in G * t(hat) : non-conformable arrays
- Error: isTRUE(gpclibPermitStatus()) is not TRUE
- How to counter the ‘non-numeric matrix extent’ error in R?
- What does is.na() applied to non-(list or vector) of type ‘NULL’ mean?
- error r: invalid subscript type “closure” in a simple regression
- Merge two rows in data.frame
- r function unzip error 1 in extracting from zip file
- Get the list of installed packages by user in R
- Colour points in a plot differently depending on a vector of values
- How to access the last value in a vector?
- increase legend font size ggplot2
- Mask output of `The following objects are masked from….:` after calling attach() function
- How To Create Vector of Vector In R
- Construct a manual legend for a complicated plot
- Code to clear all plots in RStudio
- Error: x must be atomic for ‘sort.list’
- Installing R on Android
- Transposing in dplyr
- Does the c command create a row vector or a column vector by default in R
- Convert data.frame column to a vector?
- Error in summary.connection(connection) : invalid connection
- Converting from a character to a numeric data frame
- How to create lag variables
- When trying to replace values, “missing values are not allowed in subscripted assignments of data frames”
- R Hex to RGB converter
- “pip install unroll”: “python setup.py egg_info” failed with error code 1
- beyond top level package error in relative import
- Non-numeric Argument to Binary Operator Error in R
- ModuleNotFoundError: No module named ‘sklearn’
- Editing legend (text) labels in ggplot
- Replace a value in a data frame based on a conditional (`if`) statement
- Python error: AttributeError: ‘module’ object has no attribute
- How to randomize ggplot factor color scheme, keeping same default distances on color wheel?
- Java Package Does Not Exist Error
- Count number of occurences for each unique value
- Transpose a data frame
- What’s the difference between a Python module and a Python package?
- What’s the difference between lapply and do.call?
- Download TS files from video stream
- Mean per group in a data.frame
- Error in dev.off() : cannot shut down device 1 (the null device)
- standard deviation on dataframe does not work
- What is the difference between = and ==?
- Merge r brings error “‘by’ must specify uniquely valid columns”
- Replace all particular values in a data frame
- What does the error “arguments imply differing number of rows: x, y” mean?
- Aggregate multiple columns at once
- Error in model.frame.default: variable lengths differ
- Non-numeric argument to mathematical function
- Can’t import my own modules in Python
- R – Concatenate two dataframes?
- R multiple conditions in if statement
- Simple manual RMarkdown tables that look good in HTML, PDF and DOCX
- Select rows from a data frame based on values in a vector
- Filter data.frame rows by a logical condition
- How to plot 3D scatter diagram using ggplot?
- Error in
: target of assignment expands to non-language object - Error: Invalid number of ‘breaks’ in R
- Print string and variable contents on the same line in R
- Does R have a wildcard expression (such as an asterisk (*))?
- How to melt and cast dataframes using dplyr?
- How to make rpm auto install dependencies
- use first row data as column names in r
- Launching R help: Error in file(out, “wt”) : cannot open the connection
- Reset par to the default values at startup
- How to increase the font size of ggtitle in ggplot2
- How can I remove a package from Laravel using PHP Composer?
- Getting the IP address of the current machine using Java
- “Python version 2.7 required, which was not found in the registry” error when attempting to install netCDF4 on Windows 8