Skip to content

Commit

Permalink
sent to cran
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU committed Apr 23, 2019
1 parent 55dc91d commit 244379e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This package was submitted to CRAN on 2019-04-24.
Once it is accepted, delete this file and tag the release (commit 55dc91d5aa).
2 changes: 1 addition & 1 deletion R/pretty.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ minify_json <- function( json, ... ) UseMethod("minify_json")
minify_json.json <- function( json, ... ) rcpp_minify_json( json )

#' @export
minify_json.character <- function( json, ... ) minify_json( as.json( js ) )
minify_json.character <- function( json, ... ) minify_json( as.json( json ) )

#' @export
minify_json.default <- function( json, ... ) to_json( json, ... )
Expand Down
10 changes: 9 additions & 1 deletion R/to_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ handle_digits <- function( digits ) {
return( as.integer( digits ) )
}


#' Coerce string to JSON
#'
#' @param x string to coerce to JSON
#'
#' @examples
#'
#' js <- '{"x":1,"y":2}'
#' as.json(js)
#'
#' @export
as.json <- function(x) {
if( !jsonify::validate_json( x ) )
Expand Down
7 changes: 2 additions & 5 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
## Cran submission updates

* Updates v0.1.2 to v0.2.0
* resolved [CRAN check notes](https://cran.r-project.org/web/checks/check_results_jsonify.html) by terminating C++ headers with new lines
* Support for other R SEXPTYPEs
* better handling of dates
* restructured R and c++ APIs for linking
* Updates v0.2.0 to v0.2.1
* one bug fix and one new method

## R CMD check results

Expand Down
13 changes: 0 additions & 13 deletions inst/include/jsonify/to_json/writers/complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,11 @@ namespace complex {
}
} else if ( Rf_inherits( list_element, "data.frame" ) ) {

// Rcpp::Rcout << "is data.frame" << std::endl;

Rcpp::DataFrame df = Rcpp::as< Rcpp::DataFrame >( list_element );
int n_cols = df.ncol();
int n_rows = df.nrows();
Rcpp::StringVector column_names = df.names();

// Rcpp::Rcout << "col names: " << column_names << std::endl;
// Rcpp::Rcout << "by: " << by << std::endl;
// Rcpp::Rcout << "row: " << row << std::endl;

if ( by == "column") {
writer.StartObject();

Expand Down Expand Up @@ -184,28 +178,21 @@ namespace complex {
writer.StartObject();
for( df_col = 0; df_col < n_cols; df_col++ ) {

// Rcpp::Rcout << "start_object" << std::endl;

const char *h = column_names[ df_col ];
writer.String( h );

// Rcpp::Rcout << "heading: " << h << std::endl;

SEXP this_vec = df[ h ];

switch( TYPEOF( this_vec ) ) {
case VECSXP: {
// Rcpp::Rcout << "List vec" << std::endl;
Rcpp::List lst = Rcpp::as< Rcpp::List >( this_vec );
write_value( writer, lst, unbox, digits, numeric_dates, factors_as_string, by, row );
break;
}
default: {
// Rcpp::Rcout << "switch vector" << std::endl;
switch_vector( writer, this_vec, unbox, digits, numeric_dates, factors_as_string, row );
}
} // end switch
// Rcpp::Rcout << "end_object" << std::endl;

} // end for
writer.EndObject();
Expand Down
9 changes: 0 additions & 9 deletions inst/include/jsonify/to_json/writers/simple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ namespace simple {
} else if ( factors_as_string && Rf_isFactor( iv ) ) {

Rcpp::CharacterVector lvls = iv.attr( "levels" );
//Rcpp::Rcout << "lvls: " << lvls << std::endl;
if (lvls.length() == 0 ) {
// no levels - from NA_character_ vector
Rcpp::StringVector s(1);
Expand Down Expand Up @@ -192,7 +191,6 @@ namespace simple {
Rcpp::StringVector str = Rcpp::as< Rcpp::StringVector >( iv );
write_value( writer, str, row );
}
// Rcpp::Rcout << "lvls " << lvls << std::endl;

} else {

Expand Down Expand Up @@ -273,8 +271,6 @@ namespace simple {
inline void write_value( Writer& writer, SEXP sexp, int row,
int digits, bool numeric_dates, bool factors_as_string) {

// Rcpp::Rcout << "type of sexp: " << TYPEOF( sexp ) << std::endl;

switch( TYPEOF( sexp ) ) {
case REALSXP: {
Rcpp::NumericVector nv = Rcpp::as< Rcpp::NumericVector >( sexp );
Expand All @@ -283,11 +279,6 @@ namespace simple {
}
case INTSXP: {
Rcpp::IntegerVector iv = Rcpp::as< Rcpp::IntegerVector >( sexp );
// Rcpp::Rcout << "iv: " << iv << std::endl;
// Rcpp::Rcout << "intsxp: " << iv << std::endl;
// Rcpp::Rcout << "row: " << row << std::endl;
// Rcpp::Rcout << "numeric_dates: " << numeric_dates << std::endl;
// Rcpp::Rcout << "factors_as_string: " << factors_as_string << std::endl;
// TODO( do we need factors_as_string here, or will it be sorted by the time it comes to this step?)
write_value( writer, iv, row, numeric_dates, factors_as_string );
break;
Expand Down
20 changes: 20 additions & 0 deletions man/as.json.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion tests/testthat/test-as_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@ test_that("json class set", {
js <- '{"x":[1,2,3]}'
js <- pretty_json(js)
expect_equal( attr(js, "class"), "json" )
})
})

test_that("non-characters coerced to JSON", {

# df <- data.frame(
# x = 1:5
# , y = letters[1:5]
# , stringsAsFactors = F
# )
#
# expect_true( to_json( df ) == as.json( df ) )

})

0 comments on commit 244379e

Please sign in to comment.