0

I'm a relative novice with R so bear with me. I have a piece of code that calls the function fs. When I run it, I get this message: Error in fs(x, y) : could not find function "fs" I know the function is there because I installed it with library(fs). Can anyone give me some help or advice here?

library(fs)
set.seed(33)
n = 50
p = 10
sigma = 1
x = matrix(rnorm(n*p),n,p)
beta = c(3,2,rep(0,p-2))
y = x%*%beta + sigma*rnorm(n)
# run forward stepwise, plot results
fsfit = fs(x,y) 
plot(fsfit)
# compute sequential p-values and confidence intervals
# (sigma estimated from full model) 
# out = fsInf(fsfit) 
# out
DaveS002
  • 1
  • 1
  • 2
  • 1
    When did you run `library(fs)`? Did you run it in your current R session, before you tried to call the `fs()` function? – Tim Biegeleisen Jul 24 '18 at 14:54
  • Yes, it is the first line of code that I execute. – DaveS002 Jul 24 '18 at 14:55
  • 1
    Please include your code. When you type `fs` and press enter, what do you see? – Tim Biegeleisen Jul 24 '18 at 14:56
  • Delete the above comment, and include that code directly in your question, with four or more spaces on each of code – Tim Biegeleisen Jul 24 '18 at 14:58
  • When I type fs, I get the same message. It's not found. However, it is in the User Library. – DaveS002 Jul 24 '18 at 14:58
  • Tim, code included – DaveS002 Jul 24 '18 at 15:05
  • is this a custom library called `fs` as the cran `fs` package https://cran.r-project.org/web/packages/fs/index.html doesn't seem related to your code – user20650 Jul 24 '18 at 15:06
  • One way or another, the solution will be located [here](https://stackoverflow.com/q/7027288/324364). – joran Jul 24 '18 at 15:08
  • Try `library(help = fs)`, or [see here](https://stackoverflow.com/questions/20535247/seeking-functions-in-a-package). – Tim Biegeleisen Jul 24 '18 at 15:12
  • ... additionally https://www.rdocumentation.org/packages/selectiveInference/versions/1.2.4/topics/fs – user20650 Jul 24 '18 at 15:12
  • User20650, that's the correct function at that link. I think I have the wrong one! How can two functions have the same name and how can I get the one you linked to? – DaveS002 Jul 24 '18 at 15:22
  • There are lots of packages that will have the same name for functions as they are developed independently. But the `fs` package doesn't have an `fs` function. So for your code, you will see at the link the relevant package is `selectiveInference` , so you need to install that (`install.packages("selectiveInference")`), and then call library (`library(selectiveInference)`). – user20650 Jul 24 '18 at 15:24
  • Thanks everyone! Installing the right package was the solution. – DaveS002 Jul 24 '18 at 15:30

1 Answers1

1

Try finding the package that contains your function by : help.search("fs") or ??fs

Did you installed that package ? If not do it by install.packages("yourPackage")

It may also be a namespace problem. So try first of all finding its proper Namespace by getAnywhere(fs)

Let me know the result !