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
a89fb3b3
Commit
a89fb3b3
authored
May 12, 2016
by
Holger Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added loadpack as a more powerful alternative to require_auto
parent
18006dac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
R/core_commons.R
R/core_commons.R
+34
-0
No files found.
R/core_commons.R
View file @
a89fb3b3
...
...
@@ -28,6 +28,8 @@ options(gsubfn.engine = "R")
## automatic package installation
require_auto
<-
function
(
x
){
warning
(
"require_auto is deprecated, use loadpack() instead"
)
x
<-
as.character
(
substitute
(
x
))
if
(
isTRUE
(
x
%in%
.packages
(
all.available
=
TRUE
)))
{
...
...
@@ -47,6 +49,29 @@ require_auto <- function(x){
}
}
loadpack
<-
function
(
x
){
x
<-
as.character
(
substitute
(
x
));
if
(
!
isTRUE
(
x
%in%
.packages
(
all.available
=
TRUE
))
&&
any
(
available.packages
()[,
1
]
==
x
))
{
# update.packages(ask=F) # update dependencies, if any.
eval
(
parse
(
text
=
paste
(
"install.packages('"
,
x
,
"')"
,
sep
=
""
)))
}
## if it's still missing check if it's on bioconductor
if
(
!
isTRUE
(
x
%in%
.packages
(
all.available
=
TRUE
)))
{
bcPackages
<-
as.vector
(
read.dcf
(
url
(
"https://bioconductor.org/packages/3.3/bioc/src/contrib/PACKAGES"
),
"Package"
))
if
(
any
(
bcPackages
==
x
)){
source
(
"http://bioconductor.org/biocLite.R"
)
eval
(
parse
(
text
=
paste
(
"biocLite('"
,
x
,
"', ask=FALSE)"
,
sep
=
""
)))
}
}
## load it using a library function so that loadpack errors if package is still not ins
eval
(
parse
(
text
=
paste
(
"library("
,
x
,
", quietly=T)"
,
sep
=
""
)))
}
check_version
=
function
(
pkg_name
,
min_version
)
{
cur_version
=
packageVersion
(
pkg_name
)
if
(
cur_version
<
min_version
)
stop
(
sprintf
(
"Package %s needs a newer version,
...
...
@@ -378,3 +403,12 @@ trim_outliers <- function(values, range=quantile(values, c(0.05, 0.95))) pmax(r
#limit_range <- function(values, range) pmax(range[1], pmin(range[2], values))
se
<-
function
(
x
)
sd
(
x
,
na.rm
=
TRUE
)
/
sqrt
(
sum
(
!
is.na
(
x
)))
########################################################################################################################
### Misc
## inspired by http://stackoverflow.com/questions/8343509/better-error-message-for-stopifnot
assert
<-
function
(
expr
,
error
)
{
if
(
!
expr
)
stop
(
error
,
call.
=
FALSE
)
}
\ 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