My.stepwise package installed but function not recognized

Installed stepwise regression package as below

install.packages("My.stepwise")
trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.5/My.stepwise_0.1.0.tgz'
Content type 'application/x-gzip' length 40420 bytes (39 KB)
==================================================
downloaded 39 KB

The downloaded binary packages are in
/var/folders/gk/h8604np10clcj0_75_b2pcp00000gn/T//RtmpbTdi63/downloaded_packages

WHEN I TRY to run the example from the function help window, R says the function i just installed doesn't exist

data("LifeCycleSavings")
names(LifeCycleSavings)
[1] "sr" "pop15" "pop75" "dpi" "ddpi"
dim(LifeCycleSavings)
[1] 50 5
my.variable.list <- c("pop15", "pop75", "dpi")
My.stepwise.lm(Y = "sr", variable.list = my.variable.list, in.variable = c("ddpi"),

  •            data = LifeCycleSavings)
    

Error in My.stepwise.lm(Y = "sr", variable.list = my.variable.list, in.variable = c("ddpi"), :
could not find function "My.stepwise.lm"

THANK YOU FOR YOUR HELP AND FOR THE WONDERFUL R STUDIO!

There are two steps to using a new package in R. First, you install the package (you've done that part). Then, you have to tell R to load the package. For this package, you load it with the line:

library("My.stepwise")

You'll need to load the package again at the beginning of every R session in which you intend to use the package's functions. It's good practice to put all your library() statements at the top of a script file that you use to record your analysis steps. That makes sure that everything is loaded up front, and it clearly documents which packages you are using.

People are often a little confused by this system because there's a set of core packages that R loads by default every time you launch a new session, so it's not obvious that other packages need to be loaded explicitly. (That set of core packages includes a package called datasets, which is where LifeCycleSavings in the example comes from). You might be tempted to try to make your favorite packages also load by default, and there are ways to do this — but doing so is very dangerous for reproducibility and therefore not generally advised.

1 Like