When using TermDocumentMatrix, no applicable method for 'meta' applied to an object of class character
You need to pass a proper content transformer to tm_map
, not an arbitrary character manipulating function
doc <- tm_map(doc, content_transformer(function(x)
gsub(x, pattern = "buy", replacement = "bought")))
No applicable method for 'extract_' applied to an object of class character
The problem is in this case was, as was pointed out in the comments, that the wrong library was used to execute the code. The solution therefore is to specify the library in the code:
lut <- data.table(value = names(DT))[
, variable := value %>%
shift() %>%
like("c\\d{1,2}") %>%
cumsum() %>%
magrittr::add(1L) %>%
magrittr::extract(c("id", "sex", "age", "race", "ethn"),. )][]
no applicable method for 'extract_parameter_set_dials' applied to an object of class workflow
The tidymodels packages recently had releases of dials and other packages (like workflows) that added this new generic:
library(tidymodels)
tidymodels_prefer()
data(cells, package = "modeldata")
cells <- cells[, -1] # minus case
svm_rec <- recipe(class ~ ., data = cells) |>
step_YeoJohnson(all_numeric_predictors()) |>
step_normalize(all_numeric_predictors())
svm_spec <- svm_rbf(cost = tune(), rbf_sigma = tune()) |>
set_engine("kernlab") |>
set_mode("classification")
svm_wflow <- workflow() |>
add_model(svm_spec) |>
add_recipe(svm_rec)
svm_wflow |>
extract_parameter_set_dials() |>
update(rbf_sigma = rbf_sigma(c(-7, -1)))
#> Collection of 2 parameters for tuning
#>
#> identifier type object
#> cost cost nparam[+]
#> rbf_sigma rbf_sigma nparam[+]
Created on 2022-04-02 by the reprex package (v2.0.1)
You can read more here, and we recommend updating your packages from CRAN.
no applicable method for 'prep' applied to an object of class
@importFrom recipes prep bake
had to be added to the .R file
Error in UseMethod(select) : no applicable method for 'select' applied to an object of class character
Two problems:
The first argument for your
return_coef
function is adata.frame
nameddf1
, yet you are calling it withdf1$date2
(a string). I think you should instead start withmapply(return_coef, list(df1), df1$date2, df1$Category)
(though this does error currently, see the next bullet).
The
list(df1)
in this case means that the wholedf1
will be passed as the first argument for each of the pairs fromdf1$date2
anddf1$Category
.It now fails with
argument "var1" is missing, with no default
, but I suspect you were working towards that. I'll choose a couple of random names and ... something happens.
Ultimately, the function is fine as-is, just change your mapply
use as:
mapply(return_coef, list(df1), df1$date2, df1$Category, var1 = "a1", var2 = "a2")
# [1] 6.539702 4.000000 1.000000 3.000000
Because both var1
and var2
are length-1, they are recycled for all calls to return_coef
(as their named arguments).
Since you're using dplyr
, this can be neatly put into a pipe a little more directly than using cbind(...)
:
library(dplyr)
df1 %>%
transmute(
date2, Category,
coef = mapply(return_coef, list(cur_data()), date2, Category, var1 = "a1", var2 = "a2")
)
# date2 Category coef
# 1 2021-06-27 ABC 6.539702
# 2 2021-07-01 ABC 4.000000
# 3 2021-07-02 ABC 1.000000
# 4 2021-07-03 ABC 3.000000
I use transmute
instead of a preceding select(date2, Category)
because the function needs variables present in the whole frame. I could easily have done mutate(coef=..) %>% select(date2, Category, coef)
as well.
No applicable method for 'lookup_defaults' applied to an object of class character
I'm not sure if I understand correctly, but maybe it will help
with data.table
package filtering is really easy
library(data.table)
library(dplyr)
Observation_clean <- Observation_clean %>% as.data.table()
Observation_clean_night <- Observation_clean[between(hour(date_recorded ), 6, 19) & # hours
between(as.Date(date_recorded ), as.Date("2020-11-04"), as.Date("2021-02-05")) # dates
]
Observation_clean_day <- Observation_clean[!between(hour(date_recorded ), 6, 19) & # hours
between(as.Date(date_recorded ), as.Date("2020-11-04"), as.Date("2021-02-05")) # dates
]
Related Topics
Problems Installing the Devtools Package
How to Efficiently Use Rprof in R
R Error in X$Ed:$ Operator Is Invalid for Atomic Vectors
Geometric Mean: Is There a Built-In
Test for Equality Among All Elements of a Single Numeric Vector
How to Create Grouped Barplot with R
R - Add Column That Counts Sequentially Within Groups But Repeats for Duplicates
More Than One Value for "Each" Argument in "Rep" Function
How to Remove Unicode <U+00A6> from String
How to Sort Letters in a String
Deleting Reversed Duplicates with R