Skip to content

Commit

Permalink
Merge pull request #131 from StochasticTree/pkgdown-hotfix
Browse files Browse the repository at this point in the history
Serialization and R docsite bugfixes
  • Loading branch information
andrewherren authored Jan 23, 2025
2 parents e63d809 + 2113511 commit f1e9772
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 22 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,19 @@ convertPreprocessorToJson <- function(object) {
}
if (object$num_ordered_cat_vars > 0) {
jsonobj$add_string_vector("ordered_cat_vars", object$ordered_cat_vars)
jsonobj$add_string_vector("ordered_unique_levels", object$ordered_unique_levels)
for (i in 1:object$num_ordered_cat_vars) {
var_key <- names(object$ordered_unique_levels)[i]
jsonobj$add_string(paste0("key_", i), var_key, "ordered_unique_level_keys")
jsonobj$add_string_vector(var_key, object$ordered_unique_levels[[i]], "ordered_unique_levels")
}
}
if (object$num_unordered_cat_vars > 0) {
jsonobj$add_string_vector("unordered_cat_vars", object$unordered_cat_vars)
jsonobj$add_string_vector("unordered_unique_levels", object$unordered_unique_levels)
for (i in 1:object$num_unordered_cat_vars) {
var_key <- names(object$unordered_unique_levels)[i]
jsonobj$add_string(paste0("key_", i), var_key, "unordered_unique_level_keys")
jsonobj$add_string_vector(var_key, object$unordered_unique_levels[[i]], "unordered_unique_levels")
}
}

return(jsonobj)
Expand Down Expand Up @@ -443,11 +451,21 @@ createPreprocessorFromJson <- function(json_object){
}
if (metadata$num_ordered_cat_vars > 0) {
metadata[["ordered_cat_vars"]] <- json_object$get_string_vector("ordered_cat_vars")
metadata[["ordered_unique_levels"]] <- json_object$get_string_vector("ordered_unique_levels")
ordered_unique_levels <- list()
for (i in 1:metadata$num_ordered_cat_vars) {
var_key <- json_object$get_string(paste0("key_", i), "ordered_unique_level_keys")
ordered_unique_levels[[var_key]] <- json_object$get_string_vector(var_key, "ordered_unique_levels")
}
metadata[["ordered_unique_levels"]] <- ordered_unique_levels
}
if (metadata$num_unordered_cat_vars > 0) {
metadata[["unordered_cat_vars"]] <- json_object$get_string_vector("unordered_cat_vars")
metadata[["unordered_unique_levels"]] <- json_object$get_string_vector("unordered_unique_levels")
unordered_unique_levels <- list()
for (i in 1:metadata$num_unordered_cat_vars) {
var_key <- json_object$get_string(paste0("key_", i), "unordered_unique_level_keys")
unordered_unique_levels[[var_key]] <- json_object$get_string_vector(var_key, "unordered_unique_levels")
}
metadata[["unordered_unique_levels"]] <- unordered_unique_levels
}

return(metadata)
Expand Down
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ reference:
- oneHotInitializeAndEncode
- orderedCatPreprocess
- orderedCatInitializeAndPreprocess
- convertPreprocessorToJson
- savePreprocessorToJsonString
- createPreprocessorFromJson
- createPreprocessorFromJsonString

- subtitle: Forest
desc: >
Expand Down

0 comments on commit f1e9772

Please sign in to comment.