Why do I get "Error: `...` is not empty" in R? - r

I'm a Python guy who is asked to run some R code that returns the following error:
Error: ... is not empty.
We detected these problematic arguments:
..1
These dots only exist to allow future extensions and should be empty.
Did you misspecify an argument? Run rlang::last_error() to see where
the error occurred.
I could reduce the code to this MWE:
library(dplyr)
x <- data.frame(1)
x %>% ungroup(x)
I have no idea what line 3 is supposed to do, but it fails on my system (dplyr 1.0.0), while working using dplyr 0.8.5 or on https://rdrr.io/snippets/, where it prints
X1
1 1
I have tried a number of things, with no success:
update.packages(ask = FALSE)
remove.packages("dplyr")
install.packages("dplyr")
What is going on here? How can I (help) investigate?
Update: options(error = recover) gives me this:
1: x %>% ungroup(x)
2: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
3: eval(quote(`_fseq`(`_lhs`)), env, env)
4: eval(quote(`_fseq`(`_lhs`)), env, env)
5: `_fseq`(`_lhs`)
6: freduce(value, `_function_list`)
7: withVisible(function_list[[k]](value))
8: function_list[[k]](value)
9: ungroup(., x)
10: ungroup.data.frame(., x)
11: ellipsis::check_dots_empty()
12: action_dots(action = action, message = "`...` is not empty.", dot_names = n
13: action(message, .subclass = c(.subclass, "rlib_error_dots"), ...)
14: signal_abort(cnd)
Another update: the complete line of code, non-minimized, if that matters, is
screenData <- mutate_if(screenData, is.character, as.factor) %>% ungroup(screenData)
Maybe that makes more sense than my MWE.
Another one: dput(screenData) returns
structure(list(wellID = "A001", rowID = "A0", colID = "01", value = 0,
fileName = "V3_Prob5_p1", batch = structure(NA_integer_, .Label = character(0), class = "factor"),
sampleID = NA, patientID = NA, name = NA_character_, concentration = NA_real_,
wellType = "sample"), row.names = c(NA, -1L), class = c("tbl_df",
"tbl", "data.frame"))
Finally, I opened an issue with the maintainer of the code, see https://github.com/lujunyan1118/DrugScreenExplorer/issues/1,
and with dplyr, see https://github.com/tidyverse/dplyr/issues/5368

The pipe %>% is syntactic sugar. It means "take the object on the left hand side of the pipe and use it as the first argument to the function on the right-hand side of the pipe".
So you can say ungroup(x) or x %>% ungroup(), both of which work, but x %>% ungroup(x) is trying to both ungroup a data.frame called x and remove a variable called x from the grouping of the data.frame called x. But the data.frame x doesn't contain a variable called x. Hence the problem.
The code you've been given is inherently wrong (or at the very least confusingly written).
Update
Following the post of your dput.
screenData %>% ungroup(screenData) is equivalent to ungroup(screenData, screenData) where the first screenData is the data.frame to ungroup and the second is the name of the variable in the data.frame to remove from the grouping. but the data.frame screenData does not contain a column called screenData. That's why you get an error.
The code you have been given is unequivocally incorrect.
The fact that it ran without error in a previous version of dplyr is purely accidental.

The ungroup function takes no extra arguments. The code you’ve been provided with is wrong. Remove x from the ungroup call.

It seems an issue with tibble package. See here.
Updating tibble solved the issue for me.

Related

Issue creating statcast database with BaseballR Package

I am trying to create a database of all MLB statcast outcomes. For this, I am using the baseballr package made by Bill Petti https://billpetti.github.io/2020-05-26-build-statcast-database-rstats-version-2.0/. I am not connecting to a SQL database but simply making a data frame in R. I want to collect all statcast data from 2019 and 2020. First, I loaded in the necessary packages.
library(baseballr)
library(tidyverse)
Then I executed the annual_statcast_query function:
annual_statcast_query <- function(season) {
dates <- seq.Date(as.Date(paste0(season, '-03-01')),
as.Date(paste0(season, '-12-01')), by = 'week')
date_grid <- tibble(start_date = dates,
end_date = dates + 6)
safe_savant <- safely(scrape_statcast_savant)
payload <- map(.x = seq_along(date_grid$start_date),
~{message(paste0('\nScraping week of ', date_grid$start_date[.x], '...\n'))
payload <- safe_savant(start_date = date_grid$start_date[.x],
end_date = date_grid$end_date[.x], type = 'pitcher')
return(payload)
})
payload_df <- map(payload, 'result')
number_rows <- map_df(.x = seq_along(payload_df),
~{number_rows <- tibble(week = .x,
number_rows = length(payload_df[[.x]]$game_date))}) %>%
filter(number_rows > 0) %>%
pull(week)
payload_df_reduced <- payload_df[number_rows]
combined <- payload_df_reduced %>%
bind_rows()
return(combined)
}
When I ran his code for the 2019 season payload <- annual_statcast_query(2019), I could scrape the data without any problems. However, when I tried it for 2020 payload <- annual_statcast_query(2020) I encountered the error:
Error: Can't combine `spin_rate_deprecated` <logical> and `spin_rate_deprecated` <character>.
This error occurs in the last part of the annual_statcast_query function:
combined <- payload_df_reduced %>%
bind_rows()
When reading through the statcast documentation (https://baseballsavant.mlb.com/csv-docs), it appears that the variable spin_rate_depreceated was replaced by release_spin. Perhaps this is why I am encountering this error. I do not need this variable for my analysis, and the error tracing I did made it very obvious that fixing the problem is beyond my skill set as a college student.
> rlang::last_error()
<error/vctrs_error_incompatible_type>
Can't combine `spin_rate_deprecated` <logical> and `spin_rate_deprecated` <character>.
Backtrace:
1. global::annual_statcast_query(2020)
3. dplyr::bind_rows(.)
4. vctrs::vec_rbind(!!!dots, .names_to = .id)
6. vctrs::vec_default_ptype2(...)
7. vctrs:::vec_ptype2_df_fallback(x, y, opts)
8. vctrs:::vec_ptype2_params(...)
9. vctrs:::vec_ptype2_opts(x, y, opts = opts, x_arg = x_arg, y_arg = y_arg)
11. vctrs::vec_default_ptype2(...)
12. vctrs::stop_incompatible_type(...)
13. vctrs:::stop_incompatible(...)
14. vctrs:::stop_vctrs(...)
Run `rlang::last_trace()` to see the full context.
> rlang::last_trace()
<error/vctrs_error_incompatible_type>
Can't combine `spin_rate_deprecated` <logical> and `spin_rate_deprecated` <character>.
Backtrace:
x
1. +-global::annual_statcast_query(2020)
2. | \-payload_df_reduced %>% bind_rows()
3. \-dplyr::bind_rows(.)
4. \-vctrs::vec_rbind(!!!dots, .names_to = .id)
5. \-(function () ...
6. \-vctrs::vec_default_ptype2(...)
7. \-vctrs:::vec_ptype2_df_fallback(x, y, opts)
8. \-vctrs:::vec_ptype2_params(...)
9. \-vctrs:::vec_ptype2_opts(x, y, opts = opts, x_arg = x_arg, y_arg = y_arg)
10. \-(function () ...
11. \-vctrs::vec_default_ptype2(...)
12. \-vctrs::stop_incompatible_type(...)
13. \-vctrs:::stop_incompatible(...)
14. \-vctrs:::stop_vctrs(...)
Therefore, I tried to drop this variable from my database before the bind rows operation to avoid the error.
combined <- payload_df_reduced %>%
payload_df_reduced[ , !names(payload_df_reduced) %in% c("spin_rate_deprecated")] %>%
bind_rows()
However, this returned the error message:
Error in .[payload_df_reduced, , !names(payload_df_reduced) %in% c("spin_rate_deprecated")] :
incorrect number of dimensions
I am running
packageVersion("baseballr") [1] ‘0.8.3’
On R 4.03
If anyone could help me find a way to do this, that would be amazing. I am not picky about how I get this data, so I am all ears if anyone has an idea. Thank you so much!
To drop a column from data.frame you should do this:
payload_df_reduced %>%
select(-c(spin_rate_deprecated))
or if using your current way it should be like this
payload_df_reduced[ , !names(payload_df_reduced) %in% c("spin_rate_deprecated")]
Your current code is not work because it is incorrect grammar.
It seem that your payload_df_reduced is a list of data.frame not one data.frame. I tried to run your code but it seem you have other functions so not reproducible. Here is a theory code that you may need to adjust a bit.
combined <- map(payload_df_reduced, select, -c(spin_rate_deprecated)) %>%
bind_rows()

dplyr top_n with group_by - error in as.list(x) : trying to get slot "matsin" from an object (class "quosures") that is not an S4 object

I have been successfully using the below piece of code for quite a while, but for some reason now it got broken.
Although I haved loaded the very same packages as before. No changes to R or dplyr versions in the meantime.
It looks like that dplyr's top_n() function does not work with pipes anymore.
Does anyone have experience in resolving this error message please? Any help or hint is highly appreciated.
R: 3.6.1; dplyr: 0.8.3
df %>% group_by(ID) %>% top_n(1,MRP)
Traceback:
Error in as.list(x) : trying to get slot "matsin" from an object (class "quosures") that is not an S4 object
20.
as.list(x)
19.
splice(dot_call(capture_dots, frame_env = frame_env, named = named, ignore_empty = ignore_empty, unquote_names = unquote_names, homonyms = homonyms, check_assign = check_assign))
18.
FUN(X[[i]], ...)
17.
lapply(.x, .f, ...)
16.
map(syms, function(sym) { if (!is_symbol(sym)) { abort("Inputs to capture must be argument names") } ...
15.
endots(call = sys.call(), frame_env = parent.frame(), capture_arg = rlang_enquo, capture_dots = rlang_quos_interp, named = .named, ignore_empty = .ignore_empty, unquote_names = .unquote_names, homonyms = .homonyms, check_assign = .check_assign)
14.
enquos(...)
13.
quo_reduce(..., .op = op)
12.
all_exprs(!!!dots, .vectorised = TRUE)
11.
filter.tbl_df(x, top_n_rank({ { n } ...
10.
filter(x, top_n_rank({ { n } ...
9.
top_n(., 1, MRP)
8.
function_list[[k]](value)
7.
withVisible(function_list[[k]](value))
6.
freduce(value, `_function_list`)
5.
`_fseq`(`_lhs`)
4.
eval(quote(`_fseq`(`_lhs`)), env, env)
3.
eval(quote(`_fseq`(`_lhs`)), env, env)
2.
withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
1.
df %>% group_by(ID) %>% top_n(1,MRP)
Workaround with data.table:
as.data.table(df)[,tail(.SD,1),by=ID]
Ran into the same problem due to package ycinterextra that exports its own as.list.
Possible quick fix:
library(ycinterextra)
library(dplyr)
as.list <- base::as.list
to restore as.list from base after package import statements.

Why is R not angry with my tibble: the tale of the dangling comma that could

R wants things to be just so. Commands must be exactly correct, and quite rightly so.
Thus, dangling commas are bad.
For example, on a vector:
> c(1,)
Error in c(1, ) : argument 2 is empty
Or a data frame:
> data.frame(a = 1,)
Error in data.frame(a = 1, ) : argument is missing, with no default.
But not on a tibble for some reason:
> tibble(a = 1,)
# A tibble: 1 x 1
a
<dbl>
1 1
Why is it so? What's gone ... right?
I believe that the code works because the arguments to tibble() are name-value pairs which are processed using rlang::quos().
quos() has an argument .ignore_empty = c("trailing", "none", "all").
So the default for .ignore_empty is "trailing" - i.e. the last argument to tibble is ignored if empty. If you change this, you'll see an error:
tibble(a = 1, .ignore_empty = "none",)
Error in eval_tidy(xs[[i]], unique_output) : object '' not found
See ?tibble and ?quos for the details.

R dplyr filter for non-standard evaluation (NSE) ".dots is missing, with no default"

I am hoping someone can help determine why I receive an error message when using lazy evaluation as part of a dplyr filter_ verb. The end goal is to pass arguments by reference using a function but I have narrowed the problem down outside of a function.
library(dplyr)
library(lazyeval)
library(data.table)
data_raw_dt <- data.table(
R_dates = seq(from = as.Date("2015/8/31"), by = "1 day", length.out = 30),
grp_region = sample(letters[1:4], 30, replace = TRUE),
z_valuation = rnorm(30)
)
# Create some NAs
data_raw_dt$grp_region[data_raw_dt$grp_region == "d"] <- NA
dates = "R_dates"
group = "grp_region"
column = "z_valuation"
filter_criteria = interp(~(!is.na(var)), var = as.name(group))
data_raw_dt %>%
filter_(filter_criteria)
But this gives the following error message:
"Error in lazyeval::common_env(.dots) :
argument ".dots" is missing, with no default"
In this case, I am not sure how to specify .dots and when I do it asks for a list. I have checked here, here, and here and structured my code following these examples with no success.
Package version:
dplyr 0.4.2
lazyeval 0.1.10
data table 1.9.4
Does anyone have any ideas? Thank you so much in advance!
Just replace with
filter_(.dots = filter_criteria)

Rstudio rm Error in .rs.toDataFrame names() applied to a non-vector

I have tried to deleted df(dataframe) with rm,but it is giving me an error
rm(df)
Error in .rs.toDataFrame(obj, objName, TRUE) :
names() applied to a non-vector
rm(list=as.list(df))
Error in rm(list = as.list(df)) : invalid first argument
rm(list=get('df'))
Error in rm(list = get("df")) : invalid first argument
I know how to delete objects and columns but is there efficient way to remove complete data frame in R.
dupt(df)
structure(list(Date = c("2015-08-25", "2015-08-26", "2015-08-27"
), `8552` = c(955, 2631, 2131), `8561` = c(1432, 3406, 2366)), .Names = c("Date",
"8552", "8561"), row.names = c(NA, -3L), class = "data.frame")
Thanks.
Edited
Following are some observation
df=df1
> df1
Date 8552 8561
1 2015-08-25 955 1432
2 2015-08-26 2631 3406
3 2015-08-27 2131 2366
> df
Date 8552 8561
1 2015-08-25 955 1432
2 2015-08-26 2631 3406
3 2015-08-27 2131 2366
> rm("df")
Error in .rs.toDataFrame(obj, objName, TRUE) :
names() applied to a non-vector
> df
function (x, df1, df2, ncp, log = FALSE)
{
if (missing(ncp))
.External(C_df, x, df1, df2, log)
else .External(C_dnf, x, df1, df2, ncp, log)
}
<bytecode: 0x7e43270>
<environment: namespace:stats>
Edit2
> df=1
> df
[1] 1
> rm(df)
Error in .rs.toDataFrame(obj, objName, TRUE) :
names() applied to a non-vector
i have removed df and then tried this
>df
function (x, df1, df2, ncp, log = FALSE)
{
if (missing(ncp))
.External(C_df, x, df1, df2, log)
else .External(C_dnf, x, df1, df2, ncp, log)
}
<bytecode: 0x4eb48f0>
<environment: namespace:stats>
> rm(df)
Warning message:
In rm(df) : object 'df' not found
Doesnt seems to be related with data frame.Just before removing df act like a object but as soon as I rm it,It throws an error but rm doesnt treat df as a function also.Any reason behind this abnormal behaviour.
FinalEdit
As mentioned by #RHertel:
The part with .rs.toDataFrame in the beginning of the error message makes me suspect that this error is connected with the data Viewer of RStudio. I think it could be good to start a fresh session and/or to delete all the variables in the environment (by clicking on the broom in the "Environment" tab on the upper right in RStudio). I didn't get the same error without using RStudio, e.g., when using R's standard GUI. I have not received the same error after restarting the new fresh session.
The behavior you are describing is not abnormal. In R, df() is a (rarely used) function that yields the so-called F-distribution (see ?df).
If you define a dataframe and name it df, then this variable name wil be used to store the dataframe, and you can see its content by typing dfin the console. But if you type df in the console after (successfully) deleting the dataframe with rm(df), then you obtain a description of the built-in function df; similar to the result that you get by typing any other function name without parameters like, e.g., ls instead of ls().
If you use a variable name that is not occupied by a built-in function, then the result is as expected.
Here is an example:
> my_df <- data.frame(c(1:3))
> my_df
c.1.3.
1 1
2 2
3 3
> rm(my_df)
> my_df
Error: object 'my_df' not found

Resources