Error: could not find function ... in R
There are a few things you should check :
- Did you write the name of your function correctly? Names are case sensitive.
- Did you install the package that contains the function?
install.packages("thePackage")
(this only needs to be done once) - Did you attach that package to the workspace ?
require(thePackage)
(and check its return value) orlibrary(thePackage)
(this should be done every time you start a new R session) - Are you using an older R version where this function didn't exist yet?
- Are you using a different version of the specific package? This could be in either direction: functions are added and removed over time, and it's possible the code you're referencing is expecting a newer or older version of the package than what you have installed.
If you're not sure in which package that function is situated, you can do a few things.
- If you're sure you installed and attached/loaded the right package, type
help.search("some.function")
or??some.function
to get an information box that can tell you in which package it is contained. find
andgetAnywhere
can also be used to locate functions.- If you have no clue about the package, you can use
findFn
in thesos
package as explained in this answer. RSiteSearch("some.function")
or searching with rdocumentation or rseek are alternative ways to find the function.
Sometimes you need to use an older version of R, but run code created for a newer version. Newly added functions (eg hasName in R 3.4.0) won't be found then. If you use an older R version and want to use a newer function, you can use the package backports to make such functions available. You also find a list of functions that need to be backported on the git repo of backports. Keep in mind that R versions older than R3.0.0 are incompatible with packages built for R3.0.0 and later versions.
error in could not find function in r with pipeline
%>%
is from the package "dplyr". So make sure you load it, i.e. library(dplyr)
.
Next, %>%
does not assign the result to a variable. I.e.
a %>% mutate(foo=bar(x))
does not alter a
. It will just show the result on the console (and none if you are running the script or calling it from a function).
You might be confusing the pipe-operator with %<>%
(found in the package magrittr) which uses the left-hand variable as input for the pipe, and overwrites the variable with the modified result.
Finally, when you write
If I try to assign it to a variable (e.g.
baseline <- a %>% filter(Period == "Baseline") %>% group_by(File)%>%
)
You are assigning the result from the pipeline to a variable baseline
-- this however does not modify the variable-names in the data frames (i.e. the column names).
Error: could not find function guides
The problem is solved by updating the R version. Debian Wheezy stable version ships with a version of R which is rather old. In order to update R, I followed this guidelines
http://cran.r-project.org/bin/linux/debian/
after which one has to update the old R modules
update.packages(checkBuilt = TRUE, ask = FALSE)
then the example written above works perfectly!
In R could not find function %-%
I think the function is from zeallot
library which allows assigning multiple values.
library(zeallot)
c(indices, target, segments) %<-% list(list(),list(),list())
Error in { : task 1 failed - could not find function init_status.icm
I changed the numbers of cores (ncores) to 1 in both functions (simulate and baseline) and succeed it.
control.icm actually set the core to 1 as you can see it in the image below:
https://i.stack.imgur.com/xnx69.png
Related Topics
Rearrange Dataframe to a Table, the Opposite of "Melt"
Figures Captions and Labels in Knitr
How to Get Rstudio to Automatically Compile R Markdown Vignettes
How to Identify the Distribution of the Given Data Using R
Install a Local R Package with Dependencies from Cran Mirror
Difference Between Paste() and Paste0()
How to Hide Code in Rmarkdown, with Option to See It
How to Do Selective Labeling with Ggplot Geom_Point()
Plotting the Average Values for Each Level in Ggplot2
Differences in Heatmap/Clustering Defaults in R (Heatplot Versus Heatmap.2)
Piecewise Regression with R: Plotting the Segments
Adding Custom Image to Geom_Polygon Fill in Ggplot
How to Save a Data Frame as CSV to a User Selected Location Using Tcltk
Avoid Rbind()/Cbind() Conversion from Numeric to Factor