FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
rutils.h
1 #ifndef __R_UTILS_H__
2 #define __R_UTILS_H__
3 
4 /*
5  * Copyright 2014 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of FlashR.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include <memory>
24 
25 #include<Rcpp.h>
26 
27 bool R_is_real(SEXP v);
28 bool R_is_integer(SEXP v);
29 
30 template<class T>
31 bool R_get_number(SEXP v, T &ret) {
32  if (R_is_real(v)) {
33  ret = REAL(v)[0];
34  return true;
35  }
36  else if (R_is_integer(v)) {
37  ret = INTEGER(v)[0];
38  return true;
39  }
40  else
41  return false;
42 }
43 
44 /*
45  * Test if this is a sparse matrix.
46  */
47 static inline bool is_sparse(const Rcpp::S4 &matrix)
48 {
49  std::string type = matrix.slot("type");
50  return type == "sparse";
51 }
52 
53 static inline bool is_vector(const Rcpp::S4 &vec)
54 {
55  return vec.is("fmV");
56 }
57 
58 static inline bool is_factor_vector(const Rcpp::S4 &vec)
59 {
60  return vec.is("fmFactorV");
61 }
62 
63 void R_gc();
64 SEXP R_create_s4fm(SEXP fm);
65 
66 #endif