sys.source package:base R Documentation _P_a_r_s_e _a_n_d _E_v_a_l_u_a_t_e _E_x_p_r_e_s_s_i_o_n_s _f_r_o_m _a _F_i_l_e _D_e_s_c_r_i_p_t_i_o_n: Parses expressions in the given file, and then successively evaluates them in the specified environment. _U_s_a_g_e: sys.source(file, envir = baseenv(), chdir = FALSE, keep.source = getOption("keep.source.pkgs")) _A_r_g_u_m_e_n_t_s: file: a character string naming the file to be read from envir: an R object specifying the environment in which the expressions are to be evaluated. May also be a list or an integer. The default value 'NULL' corresponds to evaluation in the base environment. This is probably not what you want; you should typically supply an explicit 'envir' argument. chdir: logical; if 'TRUE', the R working directory is changed to the directory containing 'file' for evaluating. keep.source: logical. If 'TRUE', functions keep their source including comments, see 'options(keep.source = *)' for more details. _D_e_t_a_i_l_s: For large files, 'keep.source = FALSE' may save quite a bit of memory. In order for the code being evaluated to use the correct environment (for example, in global assignments), source code in packages should call 'topenv()', which will return the name space, if any, the environment set up by 'sys.source', or the global environment if a saved image is being used. _S_e_e _A_l_s_o: 'source', and 'library' which uses 'sys.source'. _E_x_a_m_p_l_e_s: ## a simple way to put some objects in an environment ## high on the search path tmp <- tempfile() writeLines("aaa <- pi", tmp) env <- attach(NULL, name = "myenv") sys.source(tmp, env) unlink(tmp) search() aaa detach("myenv")