Commit 5b89e4ad authored by Holger Brandl's avatar Holger Brandl

fixed quotation in ci-utils

parent edbeb65b
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
......
# requires
# devtools::source_url("https://raw.githubusercontent.com/holgerbrandl/datautils/v1.43/R/core_commons.R")
# devtools::source_url("https://raw.githubusercontent.com/holgerbrandl/datautils/v1.45/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(){
}
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment