Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
datautils
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bioinfo
datautils
Commits
25eac2b2
Commit
25eac2b2
authored
Apr 11, 2017
by
Holger Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make names unique in pretty_columns
parent
63fff513
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
15 deletions
+23
-15
R/core_commons.R
R/core_commons.R
+23
-15
No files found.
R/core_commons.R
View file @
25eac2b2
...
...
@@ -133,7 +133,7 @@ install_package("tibble")
frame_data
=
function
(
...
)
tibble
::
tribble
(
...
)
add_rownames
=
function
(
...
)
tibble
::
rownames_to_column
(
...
)
add_rownames
=
function
(
...
)
{
warning
(
"DEPRECATED: Use tibble::rownames_to_column directly"
);
tibble
::
rownames_to_column
(
...
)
}
## redefine dply::splat to allow for more streamlined rowwise df-processing
...
...
@@ -198,17 +198,20 @@ push_left <- function(df, pushColNames){
#http://astrostatistics.psu.edu/datasets/R/html/base/html/formals.html
## todo does this clash with purrr::set_names
set_names
<-
function
(
df
,
...
){
#browser()
newnames
<-
as.character
(
unlist
(
list
(
...
)))
## automatically convert matrices to data.frames (otherwise the names set would fail
if
(
is.matrix
(
df
))
df
%<>%
as.data.frame
()
names
(
df
)
<-
newnames
;
return
(
df
)
}
## disabled because purrr::set_names does the same and even has the same name
# set_names <- function(df, ...){
# #browser()
# newnames <- as.character(unlist(list(...)))
#
# ## automatically convert matrices to data.frames (otherwise the names set would fail
# if(is.matrix(df)) df %<>% as.data.frame()
#
# names(df) <- newnames;
# return(df)
# }
# iris %>% purrr::set_names(paste(names(iris), "__")) %>% glimpse
# iris %>% set_names(paste(names(iris), "__")) %>% glimpse
#
#iris %>% set_names(c("setosa", "hallo")) %>% head
#iris %>% set_names("setosa", "hallo") %>% head
...
...
@@ -222,12 +225,17 @@ rify_names <- function(df){
pretty_columns
=
function
(
df
){
names
(
df
)
<-
names
(
df
)
%>%
str_replace_all
(
"[#=.,()/*: -]+"
,
"_"
)
%>%
str_replace
(
fixed
(
"["
),
""
)
%>%
str_replace
(
fixed
(
"]"
),
""
)
%>%
str_replace
(
fixed
(
"["
),
""
)
%>%
str_replace
(
fixed
(
"]"
),
""
)
%>%
## remove leading and tailing underscores
str_replace
(
"[_]+$"
,
""
)
%>%
str_replace
(
"^[_]+"
,
""
)
%>%
## remove unicode characters
iconv
(
to
=
'ASCII'
,
sub
=
''
)
%>%
## http://stackoverflow.com/questions/24807147/removing-unicode-symbols-from-column-names
tolower
;
iconv
(
to
=
'ASCII'
,
sub
=
''
)
%>%
## http://stackoverflow.com/questions/24807147/removing-unicode-symbols-from-column-names
tolower
%>%
## make duplicates unqiue
make.unique
(
sep
=
"_"
)
df
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment