Skip to content

Commit

Permalink
Don't include the external pointer for niftiHeader objects, as it won…
Browse files Browse the repository at this point in the history
…'t be updated on retrieval
  • Loading branch information
jonclayden committed Oct 19, 2018
1 parent 8d2337a commit 8c51670
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion inst/include/lib/NiftiImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ inline Rcpp::RObject NiftiImage::headerToList () const
result["intent_name"] = std::string(header.intent_name, 16);
result["magic"] = std::string(header.magic, 4);

internal::addAttributes(result, *this, false);
internal::addAttributes(result, *this, false, false);
result.attr("class") = Rcpp::CharacterVector::create("niftiHeader");

return result;
Expand Down
9 changes: 6 additions & 3 deletions inst/include/lib/NiftiImage_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ inline Rcpp::RObject imageDataToArray (const nifti_image *source)
}
}

inline void addAttributes (const SEXP pointer, const NiftiImage &source, const bool realDim = true)
inline void addAttributes (const SEXP pointer, const NiftiImage &source, const bool realDim = true, const bool includeXptr = true)
{
const int nDims = source->dim[0];
Rcpp::RObject object(pointer);
Expand All @@ -486,8 +486,11 @@ inline void addAttributes (const SEXP pointer, const NiftiImage &source, const b
object.attr("pixunits") = pixunits;
}

Rcpp::XPtr<NiftiImage> xptr(new NiftiImage(source,false));
object.attr(".nifti_image_ptr") = xptr;
if (includeXptr)
{
Rcpp::XPtr<NiftiImage> xptr(new NiftiImage(source,false));
object.attr(".nifti_image_ptr") = xptr;
}
}

#endif // USING_R
Expand Down

0 comments on commit 8c51670

Please sign in to comment.