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
Container 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
5b89e4ad
Commit
5b89e4ad
authored
Dec 08, 2017
by
Holger Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed quotation in ci-utils
parent
edbeb65b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
25 deletions
+104
-25
DESCRIPTION
DESCRIPTION
+1
-1
R/stats/ci_commons.R
R/stats/ci_commons.R
+44
-23
README.md
README.md
+59
-1
No files found.
DESCRIPTION
View file @
5b89e4ad
Package: datautils
Title: Small Utilities to make R-scripting more fun
Version: 1.45
Authors@R: person("Holger", "Brandl", email = "brandl
AEHT
mpi-cbg.de", role = c("aut", "cre"))
Authors@R: person("Holger", "Brandl", email = "brandl
@
mpi-cbg.de", role = c("aut", "cre"))
Description: Small Utilities to make R-scripting more fun
Depends: R (>= 3.4.0)
License: BSD
...
...
R/stats/ci_commons.R
View file @
5b89e4ad
# requires
# devtools::source_url("https://raw.githubusercontent.com/holgerbrandl/datautils/v1.4
3
/R/core_commons.R")
# devtools::source_url("https://raw.githubusercontent.com/holgerbrandl/datautils/v1.4
5
/R/core_commons.R")
calc_ci
=
function
(
df
,
variable
,
ci_interval
=
0.95
){
variable
<-
enquo
(
variable
)
...
...
@@ -61,7 +61,7 @@ plot_ci = function(grpData, variable, ci_interval=0.95){
## todo support model formula instead of group data
plot_interaction
=
function
(
grpData
,
variable
,
ci_interval
=
0.95
){
interaction_plot
=
function
(
grpData
,
variable
,
ci_interval
=
0.95
){
variable
<-
enquo
(
variable
)
#fail if there are more not 2 group attributes
...
...
@@ -84,50 +84,65 @@ plot_interaction = function(grpData, variable, ci_interval=0.95){
gg
=
ggplot
(
grpData
,
aes
(
x
=
eval
(
rlang
::
UQE
(
groupVar1
)),
y
=
eval
(
rlang
::
UQE
(
variable
)),
color
=
eval
(
rlang
::
UQE
(
groupVar2
))))
+
geom_jitter
(
position
=
position_jitterdodge
(
jitter.width
=
0.1
,
dodge.width
=
dodge_with
),
alpha
=
0.3
)
+
geom_errorbar
(
aes
(
ymin
=
mean
-
ci
,
ymax
=
mean
+
ci
,
y
=
NULL
),
data
=
ciData
,
width
=
.2
,
size
=
0.9
,
position
=
position_dodge
(
width
=
dodge_with
))
+
#
geom_line(aes(y = mean, group = eval(rlang::UQE(groupVar2))), position = position_dodge(width = dodge_with), data = ciData) +
geom_line
(
aes
(
y
=
mean
,
group
=
eval
(
rlang
::
UQE
(
groupVar2
))),
position
=
position_dodge
(
width
=
dodge_with
),
data
=
ciData
)
+
xlab
(
groupVar1
)
+
ylab
(
quo_name
(
variable
))
gg
}
two_way_interaction
=
function
(
grpData
,
variable
){
## invert the grouping
grpData
=
ToothGrowth
%>%
group_by
(
supp
,
as.factor
(
dose
))
groupVar1
=
groups
(
grpData
)[[
1
]]
groupVar2
=
groups
(
grpData
)[[
2
]]
regrouped
=
grpData
%>%
group_by
(
eval
(
rlang
::
UQE
(
groupVar2
)),
eval
(
rlang
::
UQE
(
groupVar1
)))
multiplot
(
interaction_plot
(
grpData
,
!!
enquo
(
variable
)),
interaction_plot
(
regrouped
,
!!
enquo
(
variable
))
)
}
########################################################################################################################
### DEV PLAYGROUND
## DEBUG-START
if
(
F
){
devtools
::
source_url
(
"https://raw.githubusercontent.com/holgerbrandl/datautils/v1.43/R/ggplot_commons.R"
)
lmModel
=
lm
(
len
~
supp
*
dose
,
data
=
ToothGrowth
)
str
(
lmModel
)
varNames
=
attr
(
attr
(
lmModel
$
terms
,
"factors"
),
"dimnames"
)[[
1
]]
grpData
=
lmModel
$
model
%>%
group_by_at
(
vars
(
one_of
(
varNames
[
2
],
varNames
[
3
])))
two_way_interaction
(
grpData
,
eval
(
parse
(
text
=
varNames
[
1
])))
ToothGrowth
%>%
group_by
(
supp
,
as.factor
(
dose
))
%>%
plot_confint
(
len
)
ToothGrowth
%>%
group_by
(
supp
,
dose
)
%>%
plot_ci
(
len
)
# ToothGrowth %>% mutate_inplace(dose, as.factor()) %>% group_by(supp, dose) %>% plot_ci(len)
.plot_confint
=
function
(
grpData
,
variable
,
ci_interval
=
0.95
)
plot_confint
(
grpData
,
quo_name
(
variable
),
ci_interval
)
interaction_plot
=
function
(
grpData
,
variable
,
ci_interval
=
0.95
){
## invert the grouping
grpData
=
ToothGrowth
%>%
group_by
(
supp
,
as.factor
(
dose
))
groupVar1
=
groups
(
grpData
)[[
1
]]
groupVar2
=
groups
(
grpData
)[[
2
]]
browser
()
regrouped
=
grpData
%>%
group_by
(
eval
(
rlang
::
UQE
(
groupVar2
)),
eval
(
rlang
::
UQE
(
groupVar1
)))
multiplot
(
.plot_confint
(
grpData
,
rlang
::
UQ
(
variable
)),
plot_confint
(
grpData
,
enquo
(
variable
)),
plot_confint
(
regrouped
,
enquo
(
variable
))
)
# .plot_confint = function(grpData, variable, ci_interval=0.95) plot_confint(grpData, quo_name(variable), ci_interval)
model_interaction
=
function
(
model
,
variable
){
lmModel
%>%
str
lmModel
$
model
}
ToothGrowth
%>%
group_by
(
supp
,
as.factor
(
dose
))
%>%
interaction_plot
(
len
)
ToothGrowth
%>%
group_by
(
supp
,
as.factor
(
dose
))
%>%
interaction_plot2
(
len
)
}
## DEBUG-END
########################################################################################################################
### DEV PLAYGROUND
if
(
F
){
# iris %>% ggplot(aes(Sepal.Width)) + geom_histogram()
...
...
@@ -162,5 +177,11 @@ if(F){
}
some_plot
(
iris
,
Petal.Length
)
foo
=
function
(){
}
}
README.md
View file @
5b89e4ad
...
...
@@ -55,6 +55,64 @@ devtools::source_url("https://raw.githubusercontent.com/holgerbrandl/datautils/m
R
-e
"devtools::create('tt')"
# move DESCRIPTION and NAMESPACE
```
in R we can load the package from sources with
```
r
devtools
::
load_all
()
```
will just load toplevel scripting directly under
`R/`
further reading https://uoftcoders.github.io/studyGroup/lessons/r/packages/lesson/
https://github.com/jtleek/rpackages
## module system for namespace isolation
How to organize large R programs? https://stackoverflow.com/a/1319786/590437
```
util = new.env()
util$bgrep = function \[...\]
util$timeit = function \[...\]
while("util" %in% search())
detach("util")
attach(util)
```
## how to install package with multiple namespaces
https://stackoverflow.com/questions/3094232/add-objects-to-package-namespace
```
r
myfun
<-
function
(
x
)
print
(
x
)
environment
(
myfun
)
<-
as.environment
(
"package:foo"
)
```
https://stackoverflow.com/questions/9002544/how-to-add-functions-in-an-existing-environment
docke testing
```
bash
docker pull rocker/tidyverse
docker run
--rm
-it
rocker/tidyverse /bin/bash
```
further reading https://uoftcoders.github.io/studyGroup/lessons/r/packages/lesson/
\ No newline at end of file
```
r
devtools
::
install_github
(
"vqv/ggbiplot"
)
```
\ No newline at end of file
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