Giter Site home page Giter Site logo

Comments (3)

bartoszukm avatar bartoszukm commented on June 18, 2024

I wanted to create print.stack, and some draft is:

Function structure("str");

// [[Rcpp::export("print.stack")]]
void stack_print(SEXP stack) {
   XPtr< S > _stack = Rcpp::as< XPtr< S > > (stack);
   int n = (*_stack).size();
   std::deque<SEXP>::iterator it = (*_stack).begin();
   for (int i=0; i < n; ++i)
   {
      structure(*it++);
   }
}

The main problem is how to print a single element, which is very general SEXP. I've found http://stackoverflow.com/questions/23462640/print-part-of-dataframe-to-screen-from-rcpp which suggests using structure.

For this solution, for exemplary code

ms = stack_create()
stack_push(ms, 1)
stack_push(ms, 2)
stack_push(ms, 3)
stack_push(ms, "maciek")
stack_push(ms, matrix(c(1,2,3,4),nrow = 2))
print.stack(ms)

I obtain a result:

num [1:2, 1:2] 1 2 3 4
chr "maciek"
num 3
num 2
num 1

Does it a desirable output?

from datastructures.

gagolews avatar gagolews commented on June 18, 2024

You can also create a print.stack function in pure R - all it does it calls print(as.list(stack)), where as.list is a function that converts all the stack's elements into a list

from datastructures.

bartoszukm avatar bartoszukm commented on June 18, 2024

97367dc also is related to this issue

from datastructures.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.