Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace stop by warning readClusterDesc #237

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ BUGFIXES :
BREAKING CHANGES :

* `api_get()` has a new parameter to control JSON file parsing
* `readClusterDesc()` return empty dataTable and warning if no cluster in Antares study.

# antaresRead 2.6.0

Expand Down
19 changes: 15 additions & 4 deletions R/readClusterDesc.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@

path <- file.path(opts$inputPath, dir)

columns = c("group","enabled","must_run","unit_count","nominal_capacity",
"min_stable_power","spinning","min_up_time","min_down_time",
"co2","marginal_cost","fixed_cost","startup_cost","market_bid_cost",
"spread_cost","ts_gen","volatility_forced","volatility_planned",
"law_forced","law_planned")

if(opts$typeLoad == 'api'){
jsoncld <- read_secure_json(paste0(path, "&depth=4"), token = opts$token, timeout = opts$timeout, config = opts$httr_config)
res <- rbindlist(mapply(function(X1, Y1){
Expand All @@ -123,9 +129,11 @@
clusters[, .SD, .SDcols = order(names(clusters))]
},jsoncld, names(jsoncld), SIMPLIFY = FALSE), fill = TRUE)

if(length(res) == 0)
stop("Cannot find cluster description.", call. = FALSE)

if(length(res) == 0){
warning("No cluster description available.", call. = FALSE)
res <- setNames(data.table(matrix(nrow = 0, ncol = 22)), c("area", "cluster", columns))

Check warning on line 134 in R/readClusterDesc.R

View check run for this annotation

Codecov / codecov/patch

R/readClusterDesc.R#L132-L134

Added lines #L132 - L134 were not covered by tests
}

res <- res[, .SD, .SDcols = c("area", "name", "group", names(res)[!names(res) %in%c("area", "name", "group")])]

}else{
Expand All @@ -146,7 +154,10 @@

}

if(length(res) == 0) stop("Cannot find cluster description.", call. = FALSE)
if(length(res) == 0){
warning("No cluster description available.", call. = FALSE)
res <- setNames(data.table(matrix(nrow = 0, ncol = 22)), c("area", "cluster", columns))

Check warning on line 159 in R/readClusterDesc.R

View check run for this annotation

Codecov / codecov/patch

R/readClusterDesc.R#L158-L159

Added lines #L158 - L159 were not covered by tests
}

res <- as.data.table(res)
setnames(res, "name", "cluster")
Expand Down
Loading