Learn R Programming

memisc (version 0.96-10)

include: Attach a Source File to the Search Path

Description

Functions include and uninclude provide a simple mechanism for modularisation without the need to code a full-blown package. Functions in an included sourcefile are attached to the search path, but are not visible in the global environment. If an experienced user has written quite a number of utility functions for her/his daily work, but does not want to have listed them in each ls() call, s/he can just include a source file containing these utility functions. uninclude just reverts the attachment of a source file into the search path. detach.sources detaches all source files from the search path.

Usage

include(filename,warn=FALSE)
uninclude(filename)
detach.sources()

Arguments

filename
character string, path to a file containing R code.
warn
logical value; should a warning issued if the file has already been included?

Examples

Run this code
include("~/R/my-functions.R")
include("~/R/more-of-my-functions.R")

ls() # The functions defined in these files will not show up here

# ... but here
search()
ls("source:~/R/my-functions.R")
ls("source:~/R/more-of-my-functions.R")

z <- one.of.my.functions(100) # ... and are available.

uninclude("~/R/my-functions.R") 

detach.sources()

Run the code above in your browser using DataLab