tidyverse

Mapply error after updating R and tidyverse

蹲街弑〆低调 提交于 2020-06-17 09:35:10
问题 I have been working on a rejection sampling code using several loops. After updating R and tidyverse I found that the code no longer works, displaying the following error: Error: Assigned data `mapply(...)` must be compatible with existing data. i Error occurred for column `sampled`. x Can't convert from <integer> to <logical> due to loss of precision. * Locations: 1. Run `rlang::last_error()` to see where the error occurred. In addition: Warning message: In seq.default(x, y, na.rm = TRUE) :

How to pass extra parameter to purrr::map with dplyr pipe

孤人 提交于 2020-06-14 15:11:54
问题 I have the following data frame and function: param_df <- data.frame( x = 1:3 + 0.1, y = 3:1 - 0.2 ) param_df #> x y #> 1 1.1 2.8 #> 2 2.1 1.8 #> 3 3.1 0.8 my_function <- function(x, y, z) { x + y + z } What I want to do is to pass param_df to my_function function but with extra parameters which don't contain in param_df , say z=3 . I tried this but failed: library(tidyverse) param_df %>% purrr::map(my_function, z =3 ) Error in .f(.x[[i]], ...) : argument "y" is missing, with no default The

How to pass extra parameter to purrr::map with dplyr pipe

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-14 15:06:43
问题 I have the following data frame and function: param_df <- data.frame( x = 1:3 + 0.1, y = 3:1 - 0.2 ) param_df #> x y #> 1 1.1 2.8 #> 2 2.1 1.8 #> 3 3.1 0.8 my_function <- function(x, y, z) { x + y + z } What I want to do is to pass param_df to my_function function but with extra parameters which don't contain in param_df , say z=3 . I tried this but failed: library(tidyverse) param_df %>% purrr::map(my_function, z =3 ) Error in .f(.x[[i]], ...) : argument "y" is missing, with no default The

How to make several for loops to perform different functions using R

*爱你&永不变心* 提交于 2020-06-13 11:45:11
问题 This is my limit point and I need R professionals to help me with a quick way of looping my codes. I have a df like: GENES <- c('RCD-7','ADF-1','BBF-10','BBF-10','BBF-10','CCF-103') pos_1 <- c ('T','G','T','A','C','T') pos_2 <- c ('G','T','A','A','C','G') df <- data.frame(GENES,pos_1,pos_2) print(df) GENES pos_1 pos_2 RCD-7 T G ADF-1 G T BBF-10 T A BBF-10 A A BBF-10 C C CCF-103 T G What I do with the df is that I want to calculate the percentage of each Nucleotide (let's say alphabet) in each

Reproducibility problems with Rmarkdown and Renv

旧街凉风 提交于 2020-06-13 08:05:53
问题 I recently noticed that the same R markdown document was generating different plots when being run in different conditions (eg. different projects). As a toy example, consider the following document: --- title: "Example" output: html_document --- ```{r plot, warning=FALSE, echo=FALSE} library("tidyverse") tibble(mu = c(-9.4, -9.3, -9.2, -9, -8.9, -8.8, -8.7, -8.5, -8.4, -8.3, 0), N = c(1, 2, 1, 1, 1, 3, 1, 1, 1, 1, 3)) %>% ggplot() + geom_point(aes(x=mu, y=N)) + geom_bar(aes(x=mu, y=N), stat=

How to melt pairwise.wilcox.test output using dplyr?

对着背影说爱祢 提交于 2020-06-09 05:44:45
问题 I want to apply pairwise.wilcox.test function using dplyr package. I am using the following code library(tidyverse) tbl_df(df)%>% pivot_longer(cols = -Class, names_to = "Wavelengths", values_to = "value") %>% group_by(Wavelengths) %>% summarize(pairwise.wilcox.test(value, as.factor(Class), p.adjust.method="bonf")$p.value) It is giving me the following error Error: Column pairwise.wilcox.test(try$value, as.factor(try$Class), p.adjust.method = "bonf")$p.value must be length 1 (a summary value),

Now that invoke() is soft-deprecated, what's the alternative?

陌路散爱 提交于 2020-06-09 04:40:06
问题 rlang::invoke() is now soft-deprecated, purrr::invoke() retired. These days, what is the tidy approach to programmatically calling a function with a list of arguments? 回答1: tldr; Use exec instead of invoke ; use map2 plus exec instead of invoke_map . Example for invoke With retired invoke set.seed(2020) invoke(rnorm, list(mean = 1, sd = 2), n = 10) #[1] 1.7539442 1.6030967 -1.1960463 -1.2608118 -4.5930686 2.4411470 #[7] 2.8782420 0.5412445 4.5182627 1.2347336 With exec set.seed(2020) exec

Why am I getting the “'…' is not empty” error mostly when using pipe and basic functions?

ε祈祈猫儿з 提交于 2020-06-09 04:12:49
问题 I am very new to R but seem to be getting this error more and more frequently, especially when using the pipe operator: "Error: ... is not empty. We detected these problematic arguments: * logical These dots only exist to allow future extensions and should be empty. Did you misspecify an argument?" I even get it on simple functions like select as in: HM_74_Duplicates_test <- HM_74_Duplicates %>% select(State) HM_74_Duplicates is loaded as a data.frame , tidyverse is in library. What am I

R combining duplicate rows by ID with different column types in a dataframe

こ雲淡風輕ζ 提交于 2020-06-01 05:59:27
问题 I have a dataframe with a column ID as an identifier and some other columns of different types (factors and numerics). It looks like this df <- data.frame(id = c(1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4), abst = c(0, NA, 2, NA, NA, NA, 0, 0, NA, 2, NA, 3, 4), farbe = as.factor(c("keine", NA, "keine", NA, NA, NA, "keine", "keine", NA, NA, NA, "rot", "rot")), gier = c(0, NA, 5, NA, NA, NA, 0, 0, NA, 1, NA, 6, 2)) Now I want to combine the duplicate IDs. The numeric columns are defined as the mean

How can I use mutate() and case_when() in a for loop?

别说谁变了你拦得住时间么 提交于 2020-05-27 21:18:47
问题 I'm writing a Shiny app where the user will be inputting data for conditions of their samples, and the script will "automatically" match their inputted conditions to sample names of a given file. For simplicity, I will not include the shiny code, because I am only struggling with the actual R implementation. If I already know what the potential conditions are, I could do something like: library(tidyverse) x <- data.frame(Samples = c('Low1', 'Low2', 'High1', 'High2', 'Ctrl1', 'Ctrl2')) x <- x