Skip to content

Commit

Permalink
Merge with Lara changes
Browse files Browse the repository at this point in the history
Merge branch 'master' of https://github.com/m-path-io/mpathr

# Conflicts:
#	R/cast_vec.R
#	R/read_mpath.R
#	R/write_mpath.R
  • Loading branch information
Koen Niemeijer committed Oct 14, 2024
2 parents cff9803 + 68d79b1 commit 9789f56
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ importFrom(dplyr,where)
importFrom(ggplot2,aes)
importFrom(ggplot2,ggplot)
importFrom(jsonlite,fromJSON)
importFrom(jsonlite,toJSON)
importFrom(lifecycle,deprecated)
importFrom(rlang,.data)
importFrom(rlang,.env)
Expand Down
4 changes: 2 additions & 2 deletions R/cast_vec.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
}

# Parse the JSON string
unjson <- jsonlite::fromJSON(unjson, simplifyVector = TRUE)
unjson <- fromJSON(unjson, simplifyVector = TRUE)

# Fill in the unjsoned values
vec[!idx_na] <- unjson
Expand All @@ -86,7 +86,7 @@
return(vec)
}

unjson <- jsonlite::fromJSON(unjson, simplifyVector = FALSE)
unjson <- fromJSON(unjson, simplifyVector = FALSE)

# The JSON is now parsed to a lists of lists of lists. We want to unlist in such a way that we
# have a list of vectors. So loop over the outer list and collapse everything into a single
Expand Down
1 change: 1 addition & 0 deletions R/mpathr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#' @importFrom ggplot2 aes
#' @importFrom ggplot2 ggplot
#' @importFrom jsonlite fromJSON
#' @importFrom jsonlite toJSON
#' @importFrom lifecycle deprecated
#' @importFrom rlang .data
#' @importFrom rlang .env
Expand Down
5 changes: 3 additions & 2 deletions R/read_mpath.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ read_meta_data <- function(
file = meta_data,
delim = ";",
locale = .mpath_locale,
escape_double = TRUE,
show_col_types = FALSE,
col_names = TRUE,
col_types = c("cccclll")
Expand Down Expand Up @@ -317,10 +318,10 @@ read_meta_data <- function(
meta_data <- meta_data |>
mutate(type = case_match(
.data$typeAnswer,
"basic" ~ "i",
"basic" ~ "?",
c("int", "integer") ~ "i",
"string" ~ "c",
"stringList" ~ "c", # the lists are read as strings and then converted to their respective types
"stringList" ~ "c",
"intList" ~ "c",
"doubleList" ~ "c",
"double" ~ "n"
Expand Down
2 changes: 1 addition & 1 deletion R/write_mpath.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ write_mpath <- function(
parsed <- vec[!idx_na]

# Parse the string to JSON
parsed <- vapply(parsed, jsonlite::toJSON, character(1))
parsed <- vapply(parsed, toJSON, character(1))

# But remove the square brackets from the JSON string
parsed <- gsub("^\\[", "", parsed)
Expand Down
4 changes: 2 additions & 2 deletions vignettes/mpathr.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ data <- read_mpath(

### Note: saving m-Path data
As explained above, the resulting data frame will contain columns with lists,
which can be problematic when saving the data. To save the data, we suggest
using either `fwrite` from the `data.table` package, or the `save` function.
which can be problematic when saving the data. To save the data, we suggest the
following two options:

If you want to save the data as a 'csv' to use it in another program, use `write_mpath()`.

Expand Down

0 comments on commit 9789f56

Please sign in to comment.