This question already has answers here:
Error: could not find function ... in R
(10 answers)
Closed 1 year ago.
I am trying to use glimpse function in R as below
df<- read.csv("movie-pang02.csv", stringsAsFactors = FALSE)
glimpse(df)
But I am getting the error:
Error: could not find function "glimpse"
Could anyone help me with it?
You'll need the dplyr package installed, first. Also, you need to have the glimpse call on a separate line.
library(dplyr)
glimpse(mtcars)
Install and load Package dplyr
library(dplyr)
First, You'll need the tibble package installed. Also, you need to have the glimpse call on a separate line
library(tibble)
glimpse(mpg)
None of the above solutions worked for me.
I was able to make it work by installing the pillar package :
install.packages("pillar")
Make sure that you run library(dplyr) first then run the glimpse() function.
Related
This question already has answers here:
Error: could not find function ... in R
(10 answers)
Closed 1 year ago.
I am not able to use is.square.matrix() function for my matrix in R.
library(tidyverse)
install.packages(c("readr", "dplyr", "haven"))
install.packages(c("psych"))
install.packages("matlib")
matr <- cov(na.omit(airquality))
is.square.matrix(matr)
I am getting error for this function could not find is.square.matrix. Can someone help mw in figuring out what I am missing here?
is.square.matrix seems to be from matrixcalc package
# // if not installed, then install the package and load it
#install.packages('matrixcalc')
library(matrixcalc)
is.square.matrix(matr)
[1] TRUE
If we don't know from which package it is loaded, then use ?? to do the check on R console and then it opens a webpage with the help pages of similar/exact functions
??is.square.matrix
gives
This question already has answers here:
Load multiple packages at once
(10 answers)
Closed 3 years ago.
Instead of loading 30 packages each with the library function is it possible to do this in a loop?
pckgs = c("readr", "dplyr")
sapply(pckgs, library)
Background:
Before loading, i test if the packages are installed. For doing so i already have the package names in the form of c("readr", ..., "dplyr") and was wondering if i can also load the package in a loop instead of writing 30 times library().
What i tried:
I simplified to one package:
sapply("readr", library)
sapply("readr", function(lib) library(lib))
sapply("readr", function(lib) library(get(lib)))
Spoiler:
I wanted to post this question and then decided to check for a "force character" in the parameter and got lucky. (It is a bit weird asking a question and answering it yourself, but when i read this i felt motivated enough :) https://stackoverflow.com/help/self-answer
The parameter character.only can be used for that.
Example:
pckgs = c("readr", "dplyr")
sapply(pckgs, library, character.only = TRUE)
I'm trying to split a column into tokens using the tokenizers package but I keep receiving an error: could not find function "unnest_tokens". I am using R 3.5.3 and have installed and reinstalled dplyr, tidytext, tidyverse, tokenizers, tidyr, but still keep receiving the error.
I have also quit and restarted R and RStudio.
comments_tidy <- comments %>%
unnest_tokens(word, txt) %>% #Break the comments into individual words
filter(!word %in% undesirable_words) %>% #Remove undesirables
anti_join(stop_words) #Data provided by the tidytext package
I receive the following:
Error in unnest_tokens(., word, txt) :
could not find function "unnest_tokens"
As mentioned in the comments, you may want to expand your code with library(x) statements. In addition, make sure that all the packages and their dependencies are installed. The following snippet would look up a given package (in this case dplyr) and install it if needed.
if ("dplyr" %in% installed.packages()[, "Package"]){
cat("'dplyr' is installed.")
} else {
install.packages("dplyr",dependencies=T)
}
library(dplyr)
The command installed.packages()[, "Package"])? gives you a list of all installed packages, that is a nice trick for debugging all kind of Function foo not found errors.
Just be sure to run this first
install.packages("tidytext")
library(tidytext)
You only need to run the first line once - it will install the package.
You need to run the second line in each new R session, since that will load the package.
Calling library (tidytext) and tidytext::unnest_tokens() solved the problem for me.
This question already has answers here:
R: use magrittr pipe operator in self written package
(4 answers)
Closed 5 years ago.
I use dplyr a lot in various functions which I am putting together into a package.
I am not supposed to use library(dplyr) ever so I am trying to double colon everything. However I cannot seem to get the dplyr version right. When I do this for example:
SurveillanceLastToNow <- function(x, A_thing, Date) {
x %>% dplyr::arrange_(A_thing, Date) %>%
dplyr::group_by_(A_thing) %>% dplyr::mutate(diffDate = difftime(Sys.Date(),
last(Date), units = "days"))
}
I get the error:
could not find function "%>%"
So my questions are
Do I need to magrittr::%>% all the way through?....surely not
Given how much I use dplyr, including most of its functions, how do I just load the whole thing on installing the package rather than :: everywhere
Basically I'm looking for the laziest way to use all the dplyr functions in my package
You can simply put dplyr into the "depends" field of description file of your package, or if you don't want attach the package into the search path, you can put it into "imports" of description, but add a line import(dplyr) in the namespace file.
My question is some packages share the same function name. How can I tell R which package that I want to use this function from?
I tried to load the package that I wanted to use again in the code but it still did not work. My case is the select in MASS and dplyr. I want to use dplyr but the error is always unused argument...
You can use the :: operator:
iris %>%
head(n = 3) %>%
dplyr::select(Sepal.Length)
See here for details.
Or detach MASS ala this post.