[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  Startup: Initialization at Start of an R Session

##  Description

In  R  , the startup mechanism is as follows.

Unless  \--no-environ  was given on the command line,  R  searches for site
and user files to process for setting environment variables. The name of the
site file is the one pointed to by the environment variable ` R_ENVIRON ` ; if
this is unset, ` [ R_HOME ](/link/R_HOME?package=base&version=3.6.2)
/etc/Renviron.site ` is used (if it exists, which it does not in a ‘factory-
fresh’ installation). The name of the user file can be specified by the `
R_ENVIRON_USER ` environment variable; if this is unset, the files searched
for are ` .Renviron ` in the current or in the user's home directory (in that
order). See ‘Details’ for how the files are read.

Then  R  searches for the site-wide startup profile file of  R  code unless
the command line option  \--no-site-file  was given. The path of this file is
taken from the value of the ` R_PROFILE ` environment variable (after [ tilde
expansion ](/link/tilde%20expansion?package=base&version=3.6.2) ). If this
variable is unset, the default is ` [ R_HOME
](/link/R_HOME?package=base&version=3.6.2) /etc/Rprofile.site ` , which is
used if it exists (which it does not in a ‘factory-fresh’ installation). (it
contains settings from the installer in a ‘factory-fresh’ installation). This
code is sourced into the  base  package. Users need to be careful not to
unintentionally overwrite objects in  base  , and it is normally advisable to
use ` [ local ](/link/local?package=base&version=3.6.2) ` if code needs to be
executed: see the examples.

Then, unless  \--no-init-file  was given,  R  searches for a user profile, a
file of  R  code. The path of this file can be specified by the `
R_PROFILE_USER ` environment variable (and [ tilde expansion
](/link/tilde%20expansion?package=base&version=3.6.2) will be performed). If
this is unset, a file called ` .Rprofile ` is searched for in the current
directory or in the user's home directory (in that order). The user profile
file is sourced into the workspace.

Note that when the site and user profile files are sourced only the  base
package is loaded, so objects in other packages need to be referred to by e.g.
` utils::dump.frames ` or after explicitly loading the package concerned.

R  then loads a saved image of the user workspace from ` .RData ` in the
current directory if there is one (unless  \--no-restore-data  or  \--no-
restore  was specified on the command line).

Next, if a function ` .First ` is found on the search path, it is executed as
` .First() ` . Finally, function ` .First.sys() ` in the  base  package is
run. This calls ` [ require ](/link/require?package=base&version=3.6.2) ` to
attach the default packages specified by ` [ options
](/link/options?package=base&version=3.6.2) ("defaultPackages") ` . If the
methods  package is included, this will have been attached earlier (by
function ` .OptRequireMethods() ` ) so that namespace initializations such as
those from the user workspace will proceed correctly.

A function ` .First ` (and ` [ .Last ](/link/.Last?package=base&version=3.6.2)
` ) can be defined in appropriate ` .Rprofile ` or ` Rprofile.site ` files or
have been saved in ` .RData ` . If you want a different set of packages than
the default ones when you start, insert a call to ` [ options
](/link/options?package=base&version=3.6.2) ` in the ` .Rprofile ` or `
Rprofile.site ` file. For example, ` options(defaultPackages = character()) `
will attach no extra packages on startup (only the  base  package) (or set `
R_DEFAULT_PACKAGES=NULL ` as an environment variable before running  R  ).
Using ` options(defaultPackages = "") ` or ` R_DEFAULT_PACKAGES="" ` enforces
the R _system_ default.

On front-e