Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add assignment operator to DimNameProxy#339

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Add assignment operator to DimNameProxy
  • Loading branch information
Florian Plaza Oñate committedAug 14, 2015
commitc5cf12560b9908667b009baf8bf24effccde1672
25 changes: 25 additions & 0 deletionsinst/include/Rcpp/vector/DimNameProxy.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,31 @@ namespace internal{
return *this;
}

inline DimNameProxy& operator=(const DimNameProxy& other) {
SEXP dim = Rf_getAttrib(data_, R_DimSymbol);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This should probably have a NULL check (same with older implementation)

if (INTEGER(dim)[dim_] != INTEGER(dim)[other.dim_]) {
std::stringstream s;
s << "dimension extent is '"
<< INTEGER(dim)[dim_]
<< "' while length of names is '"
<< INTEGER(dim)[other.dim_]
<< "'";
stop(s.str());
}
SEXP dimnames = Rf_getAttrib(data_, R_DimNamesSymbol);
SEXP dims = Rf_getAttrib(data_, R_DimSymbol);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It looks like you already retrieved this above withSEXP dim = Rf_getAttrib(data_, R_DimSymbol) -- is this line superfluous?

EDIT: I see now the interface is mostly copied from the otheroperator=; I guess that's a similar oversight in the previous implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

And while you're there, now thatstop does theprintf thing, the wholestd::stringstream can be replaced.

SEXP other_dimnames = SEXP(other);
if (Rf_isNull(dimnames)) {
Shield<SEXP> new_dimnames(Rf_allocVector(VECSXP, Rf_length(dims)));
SET_VECTOR_ELT(new_dimnames, dim_, other_dimnames);
Rf_setAttrib(data_, R_DimNamesSymbol, new_dimnames);
} else {
SET_VECTOR_ELT(dimnames, dim_, other_dimnames);
}
return *this;
}


inline operator SEXP() const {
SEXP dimnames = Rf_getAttrib(data_, R_DimNamesSymbol);
return Rf_isNull(dimnames) ? (R_NilValue) : (VECTOR_ELT(dimnames, dim_));
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp