-
Notifications
You must be signed in to change notification settings - Fork 1k
Updated error message in rbindlist to display the class attributes of mismatching columns #4822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
66f84f3
dfc8b80
d37a3cf
c99f240
4e4f62f
cce8bdf
abe9126
f8150fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -381,3 +381,38 @@ SEXP dt_zlib_version() { | |
| return ScalarString(mkChar(out)); | ||
| } | ||
|
|
||
| // Concatenate a character vector into a single CHARSXP, e.g. for printing error messages | ||
| // adapted from https://stackoverflow.com/a/58163237 | ||
| // make sure to *UNPROTECT* the returned CHARSXP after use | ||
| SEXP concatCharVec (SEXP x, const char *sep) | ||
| { | ||
| char *concatenated = NULL; /* pointer to concatenated string w/sep */ | ||
| size_t lensep = strlen (sep), /* length of separator */ | ||
| sz = 0; /* current stored size */ | ||
| int first = 1; /* flag whether first term */ | ||
|
|
||
| /* check that a character vector has been passed */ | ||
| if (TYPEOF(x) != STRSXP) | ||
| error(_("Internal error: unsupported type '%s' passed to concatCharVec()"), type2char(TYPEOF(x))); // # nocov | ||
|
|
||
| for (R_xlen_t i=0; i<xlength(x); i++) { /* for each string in s */ | ||
| size_t len = strlen (Rf_translateChar(STRING_ELT(x, i))); | ||
| /* allocate/reallocate concatenated */ | ||
| void *tmp = realloc (concatenated, sz + len + (first ? 0 : lensep) + 1); | ||
| if (!tmp) { /* validate allocation */ | ||
| error(_("Internal error: memory allocation failure in concatCharVec()")); // # nocov | ||
| } | ||
| concatenated = tmp; /* assign allocated block to concatenated */ | ||
| if (!first) { /* if not first string */ | ||
| strcpy (concatenated + sz, sep); /* copy separator */ | ||
| sz += lensep; /* update stored size */ | ||
| } | ||
| strcpy (concatenated + sz, Rf_translateChar(STRING_ELT(x, i))); /* copy string to concatenated */ | ||
| first = 0; /* unset first flag */ | ||
| sz += len; /* update stored size */ | ||
| } | ||
|
|
||
| SEXP concatenatedCharVec = PROTECT(mkChar(concatenated)); | ||
| free(concatenated); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry I think the comment got misplaced from mobile. This
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, okay. No, it's actually being called on a |
||
| return concatenatedCharVec; /* return concatenated string */ | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.