Skip to content

Commit 8ede23a

Browse files
committed
new function print()
1 parent 03a96ba commit 8ede23a

File tree

3 files changed

+44
-26
lines changed

3 files changed

+44
-26
lines changed

inst/include/Rcpp/routines.h

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,31 @@ namespace Rcpp{
3838
struct tm * gmtime_(const time_t * const);
3939
}
4040

41-
SEXP rcpp_get_stack_trace();
42-
SEXP rcpp_set_stack_trace(SEXP);
43-
std::string demangle( const std::string& name);
44-
const char* short_file_name(const char* );
45-
int* get_cache( int n );
46-
SEXP stack_trace( const char *file, int line);
47-
SEXP get_string_elt(SEXP s, int i);
48-
const char* char_get_string_elt(SEXP s, int i);
49-
void set_string_elt(SEXP s, int i, SEXP v);
50-
void char_set_string_elt(SEXP s, int i, const char* v);
51-
SEXP* get_string_ptr(SEXP s);
52-
SEXP get_vector_elt(SEXP v, int i);
53-
void set_vector_elt(SEXP v, int i, SEXP x);
54-
SEXP* get_vector_ptr(SEXP v);
55-
const char* char_nocheck( SEXP x);
56-
void* dataptr(SEXP x);
41+
SEXP rcpp_get_stack_trace();
42+
SEXP rcpp_set_stack_trace(SEXP);
43+
std::string demangle(const std::string& name);
44+
const char* short_file_name(const char* );
45+
int* get_cache(int n);
46+
SEXP stack_trace( const char *file, int line);
47+
SEXP get_string_elt(SEXP s, int i);
48+
const char* char_get_string_elt(SEXP s, int i);
49+
void set_string_elt(SEXP s, int i, SEXP v);
50+
void char_set_string_elt(SEXP s, int i, const char* v);
51+
SEXP* get_string_ptr(SEXP s);
52+
SEXP get_vector_elt(SEXP v, int i);
53+
void set_vector_elt(SEXP v, int i, SEXP x);
54+
SEXP* get_vector_ptr(SEXP v);
55+
const char* char_nocheck(SEXP x);
56+
void* dataptr(SEXP x);
5757
Rcpp::Module* getCurrentScope();
58-
void setCurrentScope( Rcpp::Module* mod );
59-
SEXP reset_current_error();
60-
int error_occured();
61-
SEXP rcpp_get_current_error();
58+
void setCurrentScope( Rcpp::Module* mod );
59+
SEXP reset_current_error();
60+
int error_occured();
61+
SEXP rcpp_get_current_error();
62+
void print(SEXP s);
6263

6364
#else
65+
6466
namespace Rcpp {
6567

6668
#define GET_CALLABLE(__FUN__) (Fun) R_GetCCallable( "Rcpp", __FUN__ )
@@ -140,6 +142,7 @@ inline attribute_hidden const char* short_file_name(const char* file) {
140142
static Fun fun = GET_CALLABLE("short_file_name");
141143
return fun(file);
142144
}
145+
143146
inline attribute_hidden SEXP stack_trace( const char *file, int line){
144147
typedef SEXP (*Fun)(const char*, int);
145148
static Fun fun = GET_CALLABLE("stack_trace");
@@ -235,11 +238,19 @@ inline attribute_hidden int error_occured(){
235238
static Fun fun = GET_CALLABLE("error_occured");
236239
return fun();
237240
}
241+
238242
inline attribute_hidden SEXP rcpp_get_current_error(){
239243
typedef SEXP (*Fun)(void);
240244
static Fun fun = GET_CALLABLE("rcpp_get_current_error");
241245
return fun();
242246
}
247+
248+
inline attribute_hidden void print(SEXP s) {
249+
typedef void (*Fun)(SEXP);
250+
static Fun fun = GET_CALLABLE("print");
251+
fun(s);
252+
}
253+
243254
#endif
244255

245256

src/Rcpp_init.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
22
//
33
// Rcpp_init.cpp : Rcpp R/C++ interface class library -- Initialize and register
44
//
5-
// Copyright (C) 2010 - 2013 John Chambers, Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2015 John Chambers, Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -116,6 +116,7 @@ void registerFunctions(){
116116
RCPP_REGISTER(reset_current_error)
117117
RCPP_REGISTER(error_occured)
118118
RCPP_REGISTER(rcpp_get_current_error)
119+
RCPP_REGISTER(print)
119120
#undef RCPP_REGISTER
120121
}
121122

src/api.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// api.cpp: Rcpp R/C++ interface class library -- Rcpp api
55
//
6-
// Copyright (C) 2012 - 2014 Dirk Eddelbuettel and Romain Francois
6+
// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
77
//
88
// This file is part of Rcpp.
99
//
@@ -56,7 +56,7 @@ using namespace Rcpp ;
5656

5757
namespace Rcpp {
5858

59-
namespace internal{
59+
namespace internal {
6060
namespace {
6161
unsigned long RNGScopeCounter = 0;
6262
}
@@ -294,8 +294,14 @@ SEXP stack_trace( const char* file, int line ){
294294
return trace ;
295295
#endif
296296
#else /* !defined( __GNUC__ ) */
297-
return R_NilValue ;
298-
#endif
297+
return R_NilValue ;
298+
#endif
299299
}
300+
301+
// [[Rcpp::register]]
302+
void print(SEXP s) {
303+
Rf_PrintValue(s); // defined in Rinternals.h
304+
}
305+
300306
// }}}
301307

0 commit comments

Comments
 (0)