Skip to content

Commit aee3c29

Browse files
committed
Revomed the dependency with respect to RJSONIO
1 parent f3af6ea commit aee3c29

3 files changed

Lines changed: 46 additions & 54 deletions

File tree

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
Package: pxR
22
Type: Package
33
Title: PC-Axis with R
4-
Version: 0.42.7
5-
Date: 2022-11-20
4+
Version: 0.42.8
5+
Date: 2025-03-24
66
Encoding: UTF-8
77
Authors@R: c(person("Carlos J.", "Gil Bellosta", email="cgb@datanalytics.com", role=c('cre', 'aut')),
88
person("Francisco J.", "Viciana", email= "franciscoj.viciana@juntadeandalucia.es", role='aut'),
99
person("Oscar", "Perpinan Lamigueiro", email="oscar.perpinan@upm.es", role='aut'),
1010
person("Emilio", "Torres Manzanera", email="torres@uniovi.es", role='ctb'))
1111
Description: Provides a set of functions for reading and writing PC-Axis files, used by different statistical organizations around the globe for data dissemination.
12-
Depends: stringr, reshape2, RJSONIO, plyr
12+
Depends: stringr, reshape2, jsonlite, plyr
1313
URL: https://github.com/cjgb/pxR
1414
License: GPL-3
1515
LazyLoad: yes

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ importFrom("stringr", str_split, str_locate_all, str_sub, str_length)
55
importFrom("plyr", mapvalues, ldply)
66
importFrom("stats", "formula", "ftable")
77
importFrom("utils", "read.table", "str")
8-
importFrom("RJSONIO", "toJSON")
8+
importFrom("jsonlite", "write_json")
99

1010

1111
export(read.px)

R/write.json.stat.R

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,56 @@
11
#################################################################
2-
#
2+
#
33
# File: write.json.stat.R
44
# Purpose: Write an object of class 'px' a file with json-stat format
55
# See http://json-stat.org/
66
#
77
# Created: 20130813
88
# Authors: cjgb
99
#
10-
# Modifications:
10+
# Modifications:
11+
# cjgb, 20250324 - Remove the dependency on RJSONIO
1112
#
1213
#################################################################
1314

1415

15-
write.json.stat <- function ( obj.px, filename ){
16-
17-
if ( ! inherits( obj.px, "px" ) )
18-
stop("Error: object needs to have class 'px'" )
19-
20-
aa <- as.array(obj.px)
16+
write.json.stat <- function(obj.px, filename){
17+
18+
if (! inherits(obj.px, "px"))
19+
stop("Error: object needs to have class 'px'")
20+
21+
aa <- as.array(obj.px)
22+
js.dim.id <- names(dimnames(aa))
23+
js.dim.size <- sapply(dimnames(aa), length)
24+
names(js.dim.size) <- NULL
25+
26+
js.dim.ids <- lapply(
27+
dimnames(aa),
28+
function(x) {
29+
list(category = list(index = x))
30+
}
31+
)
32+
33+
js.value <- as.numeric(aa)
34+
js.updated <- as.character(Sys.time())
35+
js.source <- obj.px$SOURCE$value
36+
js.label <- obj.px$TITLE$value
37+
38+
js <- list(
39+
label = js.label,
40+
source = js.source,
41+
updated = js.updated,
42+
value = js.value,
43+
dimension = c(list(id = js.dim.id, size = js.dim.size ), js.dim.ids)
44+
)
45+
46+
js <- list(js)
47+
names(js) <- obj.px$MATRIX$value
2148

22-
js.dim.id <- names(dimnames(aa))
23-
24-
js.dim.size <- sapply(dimnames(aa), length)
25-
names(js.dim.size) <- NULL
26-
27-
js.dim.ids <- lapply( dimnames(aa),
28-
function(x){
29-
list( category = list( index = x ) )
30-
31-
}
32-
)
33-
34-
js.value <- as.numeric(aa)
35-
36-
js.updated <- as.character(Sys.time())
37-
js.source <- obj.px$SOURCE$value
38-
js.label <- obj.px$TITLE$value
39-
40-
41-
js <- list( label = js.label,
42-
source = js.source,
43-
updated = js.updated,
44-
value = js.value,
45-
dimension = c( list( id = js.dim.id,
46-
size = js.dim.size ),
47-
48-
js.dim.ids
49-
50-
)
51-
)
52-
53-
js <- list(js)
54-
names(js) <- obj.px$MATRIX$value
55-
56-
57-
# encoding must be UTF-8 for json files
58-
con <- file( description = filename, open = "w", encoding = "UTF-8" )
59-
on.exit( close(con) )
60-
61-
cat(toJSON(js), file = con)
62-
63-
}
49+
write_json(
50+
js,
51+
path = filename,
52+
auto_unbox = TRUE,
53+
pretty = TRUE,
54+
encoding = "UTF-8")
6455

56+
}

0 commit comments

Comments
 (0)