Skip to content

Commit

Permalink
Combine and check dimnames in one function
Browse files Browse the repository at this point in the history
Combine dimnames and check them in one function instead of calling
xts_merge_make_colnames() after xts_merge_combine_dimnames() in two
places in the code.
  • Loading branch information
joshuaulrich committed Feb 12, 2024
1 parent f53821a commit 1caba4c
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ SEXP xts_merge_make_colnames (SEXP colnames, SEXP suffixes, SEXP check_names, SE
return(newcolnames);
}

SEXP xts_merge_combine_dimnames (SEXP _x, SEXP _y, int ncol_x, int ncol_y, SEXP _orig_colnames)
SEXP xts_merge_make_dimnames (SEXP _x, SEXP _y, int ncol_x, int ncol_y,
SEXP _orig_colnames, SEXP _suffixes, SEXP _check_names, SEXP _env)
{
int p = 0;
int ncols = ncol_x + ncol_y;
Expand Down Expand Up @@ -103,11 +104,16 @@ SEXP xts_merge_combine_dimnames (SEXP _x, SEXP _y, int ncol_x, int ncol_y, SEXP
}
}

colnames = PROTECT(xts_merge_make_colnames(colnames, _suffixes, _check_names, _env)); p++;

SEXP dimnames = PROTECT(allocVector(VECSXP, 2)); p++;
SET_VECTOR_ELT(dimnames, 0, R_NilValue);
SET_VECTOR_ELT(dimnames, 1, colnames);

UNPROTECT(p);
return(colnames);
return(dimnames);
}


/*
* These macros allow _XTS_DO_MERGE_ to handle character xts objects as well
* as all the other storage types.
Expand Down Expand Up @@ -491,13 +497,7 @@ SEXP do_merge_xts (SEXP x, SEXP y,
/* dimnames */
if (!isNull(colnames)) {
/* only set DimNamesSymbol if passed colnames is not NULL */
SEXP newcolnames = PROTECT(xts_merge_combine_dimnames(x, y, ncx, ncy, colnames)); p++;
newcolnames = PROTECT(xts_merge_make_colnames(newcolnames, suffixes, check_names, env)); p++;

SEXP dimnames = PROTECT(allocVector(VECSXP, 2)); p++;
SET_VECTOR_ELT(dimnames, 0, R_NilValue);
SET_VECTOR_ELT(dimnames, 1, newcolnames);

SEXP dimnames = PROTECT(xts_merge_make_dimnames(x, y, ncx, ncy, colnames, suffixes, check_names, env)); p++;
setAttrib(result, R_DimNamesSymbol, dimnames);
}

Expand Down Expand Up @@ -672,13 +672,7 @@ SEXP do_merge_xts (SEXP x, SEXP y,
/* DIMNAMES */
if (!isNull(colnames)) {
/* only set DimNamesSymbol if passed colnames is not NULL */
SEXP newcolnames = PROTECT(xts_merge_combine_dimnames(x, y, ncx, ncy, colnames)); p++;
newcolnames = PROTECT(xts_merge_make_colnames(newcolnames, suffixes, check_names, env)); p++;

SEXP dimnames = PROTECT(allocVector(VECSXP, 2)); p++;
SET_VECTOR_ELT(dimnames, 0, R_NilValue);
SET_VECTOR_ELT(dimnames, 1, newcolnames);

SEXP dimnames = PROTECT(xts_merge_make_dimnames(x, y, ncx, ncy, colnames, suffixes, check_names, env)); p++;
setAttrib(result, R_DimNamesSymbol, dimnames);
}
} else {
Expand Down

0 comments on commit 1caba4c

Please sign in to comment.