skranz / dplyrextras Goto Github PK
View Code? Open in Web Editor NEWSome extra functionality that is not (yet) in dplyr, e.g. mutate_rows or s_filter, s_arrange ,...
Some extra functionality that is not (yet) in dplyr, e.g. mutate_rows or s_filter, s_arrange ,...
iris %>% group_by(Species) %>% mutate_if(Sepal.Length > mean(Sepal.Length), Sepal.Length = 5)
Error: object 'INDEX.ROW__' not found
Hi, Stephan
Thanks for creating these functions - they're really helpful. There seems to be a bug in the documentation of the various s_ functions. In the code snippet, you create what seems to be a vector of character variables, as follows:
cols = c("mpg","cyl, hp:vs")
Shouldn't that be cols = c("mpg", "cyl", "hp:vs") #i.e. each one is a separate quoted variable, rather than having one variable containing "cyl, hp:vs"
install_github(repo="dplyrExtras", username="skranz")`
returns an error:
Warning message:
Username parameter is deprecated. Please use skranz/dplyrExtras
Code needs to be:
library(devtools); install_github(repo="skranz/dplyrExtras")
s_recode <- function(.x, ..., .default = NULL, .missing = NULL) {
eval.string.PAT.named_dots.default.missing(.x, "recode", .default, .missing, ...)
}
eval.string.PAT.named_dots.default.missing <- function(.x, .fun.name, .default, .missing, ...) {
args = list(...)
args = unlist(args)
args = paste0(names(args), " = ", args)
DEFAULT = if(!is.null(.default)) { paste0(", .default = ", .default) } else { "" }
MISSING = if(!is.null(.missing)) { paste0(", .missing = ", .missing) } else { "" }
code = paste0(.fun.name,"(.x, ", paste0(args, collapse=", "), DEFAULT, MISSING, ")" )
v = eval(parse(text=code,srcfile=NULL))
v
}
SQuote <- function(x) { sapply( x , function(xx) { paste0("'", xx, "'") }, USE.NAMES = FALSE ) }
# > SQuote(letters[1:3])
# [1] "'a'" "'b'" "'c'"
new_letters <- SQuote(c("alpha", "beta"))
names(new_letters) <- c("a","b")
# > new_letters
# a b
# "'alpha'" "'beta'"
# > s_recode(letters[1:3], new_letters)
# [1] "alpha" "beta" "c"
# > s_recode(letters[1:3], new_letters, .default = "'gamma'")
# [1] "alpha" "beta" "gamma"
Hello. I use mutate_rows a lot and I just started getting an error message on code that used to work fine, which I suspect has something to do with the update to dplyr 0.7.0.
For example, the code
library(dplyr)
library(dplyrExtras)
df <- tibble(a = c(1,2,1), b = letters[2:4])
df %>% mutate_rows(a == 1, b = "hello")
leads to the following error message Error in get(name, envir = asNamespace(pkg), inherits = FALSE) : object 'named_dots' not found'
Since named_dots
is a dplyr function, I'm guessing that's where the issue is. Is there a fix that you can implement in dplyrExtras to get around whatever was changed in the dplyr update?
The original issue is here: tidyverse/dplyr#1307
Variable labels are one of the few remaining features that are nicer in Stata. These are used for variable descriptions that are longer than appropriate for a title.
The call would be something like:
my_tbl_df %>% select(my_var_1, my_var_2) %>% labels()
And the output would be a character vector of the variable labels for my_var_1
and my_var_2
.
Might be a good addition to dplyrExtras!
The current version of mutate_if.data.frame
seems to call as.data.frame
in the first line. I think it should be as.data.table
. Because later you call mutate_if.data.table
on the newly created dt
.
mutate_if.data.frame =function (.data,.if,...)
{
dt = as.data.table(.data) # changed from dt = as.data.frame(.data)
.if.quoted = substitute(.if)
as.data.frame(mutate_if.data.table(.data=dt,.if.quoted=.if.quoted,...,inplace=TRUE, .parent.env = parent.frame()))
}
Dear Sebastian,
I really like your mutate_if function ! To your knowledge what is the best way to implement this function tbl_sqlite object ?
Cheers
Clément
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.