Skip to content

Commit 12e0626

Browse files
authored
Merge pull request #26 from pepkit/dev
v0.1
2 parents 0228eca + c927288 commit 12e0626

21 files changed

Lines changed: 367 additions & 103 deletions

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: pepr
22
Type: Package
33
Title: Reading Portable Encapsulated Projects
4-
Version: 0.0.4
4+
Version: 0.1
55
Date: 2017-08-09
66
Authors@R: c(person("Nathan", "Sheffield", email = "nathan@code.databio.org",
77
role = c("aut", "cre")),person("Michal","Stolarczyk",email="mjs5kd@virginia.edu",role=c("ctb")))
@@ -19,4 +19,4 @@ Suggests:
1919
VignetteBuilder: knitr
2020
License: BSD_2_clause + file LICENSE
2121
BugReports: https://github.com/pepkit/pepr
22-
RoxygenNote: 6.1.0
22+
RoxygenNote: 6.1.1

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(.expandPath)
4+
export(.listifyDF)
45
export(.printNestedList)
56
export(.strformat)
67
export(Project)
8+
export(activateSubproject)
79
export(config)
10+
export(fetchSamples)
811
export(getSample)
912
export(getSubsample)
1013
export(listSubprojects)
1114
export(samples)
1215
exportClasses(Config)
1316
exportClasses(Project)
17+
exportMethods(checkSection)
1418
import(pryr)
1519
import(stringr)
1620
import(yaml)

NEWS.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,54 @@
1-
# pepr 0.0.4
1+
# pepr 0.0.5
22

33
## TBA
44

5-
## New Functionalites
5+
## Added
6+
7+
* add `activateSubproject` method
8+
* add `fetchSamples` function
9+
* add `checkSection` method on `Config` object
10+
11+
## Changed
12+
13+
* if the `subproject` argument of the `Project()` function is not present in the config, the original project is returned
14+
* paths in the `bioconductor` section of the config are made aboslute and environment varaiables are read
15+
* no sample annotation is allowed if any suprojects are defined in the config
16+
* fixed the problem with paths expansions in sample subannotaitons case
17+
18+
19+
# pepr 0.0.4
20+
21+
## 2018-11-14
22+
23+
## Added
624

7-
## Changes
25+
## Changed
826

927
* change the `Project` object construction, the subproject can be activated at construction time
1028
* change `implied/derived_columns` to `implied/derived_attributes`. Backwards compatible
1129
* change `constants` to `constantAttributes`. Backwards compatible
12-
13-
## Bug Fixes
14-
1530
* fix `expandPath()` function, add error when environment variable not found
1631

1732

1833
# pepr 0.0.3
1934

2035
## 2018-09-12
2136

22-
## New Functionalities
37+
## Added
2338

2439
* add `derived_columns` functionality
2540
* add `implied_columns` functionality
2641
* add `subannotation` functionality
2742

28-
## Changes
29-
30-
## Bug Fixes
31-
43+
## Changed
3244

3345
# pepr 0.0.2
3446

3547
## 2018-09-06
3648

37-
## New Functionalites
49+
## Added
3850

3951
* first release, includes basic [PEP](https://pepkit.github.io/) reading functions
4052

41-
## Changes
42-
43-
## Bug Fixes
53+
## Changed
4454

R/loadConfig.R

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#' @param filename file path to config file
77
#'
88
#' @seealso \url{https://pepkit.github.io/}
9-
.loadConfig = function(filename = NULL, sp = NULL) {
9+
.loadConfig = function(filename=NULL, sp=NULL) {
1010
if (!file.exists(filename)) {
1111
stop("No config file found")
1212
}
@@ -17,11 +17,11 @@
1717
cfg = methods::new("Config", config_file)
1818

1919
if (is.null(cfg)) {
20-
cat("Config file not loaded.", fill = T)
20+
message("Config file not loaded.")
2121
return()
2222
}
2323

24-
cat("Loaded config file: ", filename, fill = T)
24+
message("Loaded config file: ", filename)
2525

2626
# Show available subprojects
2727
.listSubprojects(cfg)
@@ -34,7 +34,14 @@
3434
mdn = names(cfg$metadata)
3535

3636
cfg$metadata = .makeMetadataSectionAbsolute(cfg, parent = dirname(filename))
37-
37+
# make data_sources section absolute
38+
if(!is.null(cfg$data_sources))
39+
cfg$data_sources = lapply(cfg$data_sources, .expandPath)
40+
# make bioconductor$read_fun_path value absolute, used in BiocProject
41+
if(!is.null(cfg$bioconductor$read_fun_path)){
42+
path = gsub("\\./","",cfg$bioconductor$read_fun_path)
43+
cfg$bioconductor$read_fun_path = .makeAbsPath(path, parent=dirname(filename))
44+
}
3845
# Infer default project name
3946

4047
if (is.null(cfg$name)) {
@@ -47,33 +54,41 @@
4754
}
4855
cfg$name = maybeProjectName
4956
}
50-
5157
return(cfg)
5258
}
5359

5460
.updateSubconfig = function(cfg, sp = NULL) {
5561
if (!is.null(sp)) {
5662
if (is.null(cfg$subprojects[[sp]])) {
57-
cat("Subproject not found: ", sp, fill = T)
58-
return()
63+
warning("Subproject not found: ", sp)
64+
message("Subproject was not activated")
65+
return(cfg)
5966
}
6067
cfg = utils::modifyList(cfg, cfg$subprojects[[sp]])
61-
cat("Loading subproject: ", sp, fill = T)
68+
message("Loading subproject: ", sp)
6269
}
6370
return(cfg)
6471
}
6572

6673

6774

68-
.listSubprojects = function(cfg) {
75+
.listSubprojects = function(cfg, style="message") {
76+
# this function can be used in object show method, where cat is preferred
77+
# or for user information when the Project is created, where message
78+
# is preferred
79+
if(!style == "message"){
80+
printFun = pryr::partial(cat, fill = T)
81+
}else{
82+
printFun = message
83+
}
6984
# make sure the extracted config is of proper class
7085
if(!methods::is(cfg,"Config"))
7186
stop("The Project object does not contain a vaild config")
7287

7388
if (length(names(cfg$subprojects)) > 0) {
7489
# If there are any show a cat and return if needed
75-
cat(" subprojects: ", paste0(names(cfg$subprojects),
76-
collapse = ","), fill = T)
90+
printFun(" subprojects: ", paste0(names(cfg$subprojects),
91+
collapse = ","))
7792
invisible(names(cfg$subprojects))
7893
} else{
7994
# Otherwise return NULL for testing purposes
@@ -139,7 +154,7 @@
139154
}
140155

141156
# if it's a path, make it absolute
142-
path = path.expand(path)
157+
path = normalizePath(path.expand(path),mustWork = FALSE)
143158
# search for env vars, both bracketed and not
144159
matchesBracket = gregexpr("\\$\\{\\w+\\}", path, perl = T)
145160
matches = gregexpr("\\$\\w+", path, perl = T)
@@ -148,7 +163,6 @@
148163
# this way both bracketed and not bracketed ones will be replaced
149164
if(all(attr(matchesBracket[[1]], "match.length") != -1)) path = replaceEnvVars(path, matchesBracket)
150165
if(all(attr(matches[[1]], "match.length") != -1)) path = replaceEnvVars(path, matches)
151-
152166
return(path)
153167
}
154168

@@ -165,13 +179,16 @@
165179
#' @param exclude character vector of args that should be excluded from
166180
#' the interpolation. The elements in the vector should match the names of the
167181
#' elements in the \code{args} list
182+
#' @param parent a directory that will be used to make the path absolute
168183
#' @export
169184
#' @examples
170185
#' .strformat("~/{VAR1}{VAR2}_file", list(VAR1="hi", VAR2="hello"))
171186
#' .strformat("$HOME/{VAR1}{VAR2}_file", list(VAR1="hi", VAR2="hello"))
172-
.strformat = function(string, args, exclude) {
187+
.strformat = function(string, args, exclude, parent=NULL) {
173188
result = c()
174-
x = .expandPath(string)
189+
# if parent provided, make the path absolute and expand it.
190+
# Otherwise, just expand it
191+
x = ifelse(is.null(parent),.expandPath(string),.makeAbsPath(string, parent))
175192
# str_interp requires variables encoded like ${var}, so we substitute
176193
# the {var} syntax here.
177194
x = stringr::str_replace_all(x, "\\{", "${")
@@ -230,5 +247,7 @@
230247
}
231248
absoluteMetadata[[metadataAttribute]] = values
232249
}
250+
251+
233252
return(absoluteMetadata)
234253
}

0 commit comments

Comments
 (0)