Comments (3)
Perhaps, something along the lines of this would suit you. You can give it (pretty much) what you like:
set_names <- function(x, ...)
{
dots <- as.list(substitute(list(...))[-1])
nms <-
lapply(dots, function(dot) {
if (is.symbol(dot))
as.character(dot) else
eval(dot, parent.frame(), parent.frame())
})
setNames(x, unlist(nms))
}
iris %>%
head %>%
set_names("a", b, list("c", c("d", "e")))
from magrittr.
It's great, thanks
from magrittr.
Maybe even
name_setter <- function(FUN)
{
function(x, ...)
{
dots <- as.list(substitute(list(...))[-1])
nms <-
lapply(dots, function(dot) {
if (is.symbol(dot))
as.character(dot) else
eval(dot, parent.frame(), parent.frame())
})
FUN(x, unlist(nms))
}
}
set_names <- name_setter(setNames)
set_colnames <- name_setter(`colnames<-`)
set_rownames <- name_setter(`rownames<-`)
from magrittr.
Related Issues (20)
- Sequential pipe operator? HOT 9
- Feature request: Assignment expression operator HOT 1
- Move `master` branch to `main` HOT 1
- `magrittr::freduce()` doesn't support lambda functions HOT 4
- Add warning when piped object overwrites keyword arguments when not used as first argument HOT 1
- Inconsistent assign() behavior in simple piping with Magrittr HOT 1
- Bug: Rstudio completion with "mrgmod" S4 class object HOT 4
- Feature: Function to create functional sequences HOT 1
- Suggest alias for `Encoding<-` HOT 1
- Hartmann pipelines HOT 3
- Magrittr Logo HOT 1
- difference in performance HOT 2
- Different results using pipes HOT 2
- introspection HOT 2
- magrittr upkeep 2023
- Add function not behaving correctly when being fed an expression
- Pipe doesn't work in basic round function HOT 1
- Question: magrittr's pipes not hyperlinked in docs, why not?
- Question: UN or UNE pipe? HOT 1
- Assignment pipe `%<>%` breaks if R-native `|>` pipes used in chain instead of magrittr-native pipes `%>%` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magrittr.