Python rpy2.robjects.IntVector() Examples
The following are 30
code examples of rpy2.robjects.IntVector().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rpy2.robjects
, or try the search function
.
Example #1
Source File: common.py From Computable with MIT License | 6 votes |
def _convert_vector(obj): if isinstance(obj, robj.IntVector): return _convert_int_vector(obj) elif isinstance(obj, robj.StrVector): return _convert_str_vector(obj) # Check if the vector has extra information attached to it that can be used # as an index try: attributes = set(r['attributes'](obj).names) except AttributeError: return list(obj) if 'names' in attributes: return pd.Series(list(obj), index=r['names'](obj)) elif 'tsp' in attributes: return pd.Series(list(obj), index=r['time'](obj)) elif 'labels' in attributes: return pd.Series(list(obj), index=r['labels'](obj)) if _rclass(obj) == 'dist': # For 'eurodist'. WARNING: This results in a DataFrame, not a Series or list. matrix = r['as.matrix'](obj) return convert_robj(matrix) else: return list(obj)
Example #2
Source File: network.py From iterativeWGCNA with GNU General Public License v2.0 | 6 votes |
def plot_module_eigengene(self, module): ''' barchart illustrating module eigengene ''' eigengene = self.eigengenes.get_module_eigengene(module) params = {} params['height'] = base().as_numeric(eigengene) limit = max(abs(base().max(eigengene)[0]), abs(base().min(eigengene)[0])) ylim = [-1 * limit, limit] params['ylim'] = ro.IntVector(ylim) colors = ["red" if e[0] > 0 else "blue" for e in eigengene] params['col'] = ro.StrVector(colors) params['border'] = ro.NA_Logical params['las'] = 2 params['names.arg'] = ro.StrVector(self.eigengenes.samples()) params['cex.names'] = 0.6 params['main'] = "Eigengene: " + module manager = RManager(eigengene, params) manager.barchart()
Example #3
Source File: wgcna.py From iterativeWGCNA with GNU General Public License v2.0 | 6 votes |
def plot_eigengene_network(self): ''' wrapper for plotEigengeneNetworks function plots an eigengene network ''' params = {} params['multiME'] = base().as_data_frame(self.transpose_data()) params['setLabels'] = '' params['marDendro'] = ro.IntVector([0, 4, 1, 2]) params['marHeatmap'] = ro.IntVector([3, 4, 1, 2]) params['cex.lab'] = 0.8 params['xLabelsAngle'] = 90 params['colorLabels'] = False params['signed'] = True wgcna().plotEigengeneNetworks(**params)
Example #4
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_sample_replacement(): vec = robjects.IntVector(range(100)) spl = vec.sample(110, replace=True) assert len(spl) == 110
Example #5
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_r_ne(): v = robjects.vectors.IntVector((4, 2, 1)) res = v.ro != 2 assert all(x is y for x, y in zip(res, (True, False, True)))
Example #6
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_r_neg(): v = robjects.vectors.IntVector((4, 2, 1)) res = - v.ro assert all(x is y for x, y in zip(res, (-4, -2, -1)))
Example #7
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_getnames(): vec = robjects.vectors.IntVector(array.array('i', [1,2,3])) v_names = [robjects.baseenv["letters"][x] for x in (0,1,2)] #FIXME: simplify this r_names = robjects.baseenv["c"](*v_names) vec = robjects.baseenv["names<-"](vec, r_names) for i in range(len(vec)): assert v_names[i] == vec.names[i] vec.names[0] = 'x'
Example #8
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_setnames(): vec = robjects.vectors.IntVector(array.array('i', [1,2,3])) names = ['x', 'y', 'z'] vec.names = names for i in range(len(vec)): assert names[i] == vec.names[i]
Example #9
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_tabulate(): vec = robjects.IntVector((1,2,1,2,1,2,2)) tb = vec.tabulate() assert tuple(tb) == (3, 4)
Example #10
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_int_repr(): vec = robjects.vectors.IntVector((1, 2, ri.NA_Integer)) s = repr(vec) assert s.endswith('[1, 2, NA_integer_]')
Example #11
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_items(): vec = robjects.IntVector(range(3)) vec.names = robjects.StrVector('abc') names = [k for k,v in vec.items()] assert names == ['a', 'b', 'c'] values = [v for k,v in vec.items()] assert values == [0, 1, 2]
Example #12
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_itemsnonames(): vec = robjects.IntVector(range(3)) names = [k for k,v in vec.items()] assert names == [None, None, None] values = [v for k,v in vec.items()] assert values == [0, 1, 2]
Example #13
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_sequence_to_vector(): res = robjects.sequence_to_vector((1, 2, 3)) assert isinstance(res, robjects.IntVector) res = robjects.sequence_to_vector((1, 2, 3.0)) assert isinstance(res, robjects.FloatVector) res = robjects.sequence_to_vector(('ab', 'cd', 'ef')) assert isinstance(res, robjects.StrVector) with pytest.raises(ValueError): robjects.sequence_to_vector(list())
Example #14
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_sample_probabilities(): vec = robjects.IntVector(range(100)) spl = vec.sample(10, probabilities=robjects.FloatVector([.01] * 100)) assert len(spl) == 10
Example #15
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_sample_probabilities_novector(): vec = robjects.IntVector(range(100)) spl = vec.sample(10, probabilities=[.01] * 100) assert len(spl) == 10
Example #16
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_sample_probabilities_error_len(): vec = robjects.IntVector(range(100)) with pytest.raises(ValueError): vec.sample(10, probabilities=robjects.FloatVector([.01] * 10))
Example #17
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_sample_error(): vec = robjects.IntVector(range(100)) with pytest.raises(ri.embedded.RRuntimeError): spl = vec.sample(110)
Example #18
Source File: test_vector.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_r_gt(): v = robjects.vectors.IntVector((4, 2, 1)) res = v.ro > 2 assert all(x is y for x, y in zip(res, (True, False, False)))
Example #19
Source File: test_array.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_ncol_get(): m = robjects.r.matrix(robjects.IntVector(range(6)), nrow=3, ncol=2) assert m.ncol == 2
Example #20
Source File: test_array.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_transpose(): m = robjects.r.matrix(robjects.IntVector(range(6)), nrow=3, ncol=2) mt = m.transpose() for i,val in enumerate((0,1,2,3,4,5,)): assert m[i] == val for i,val in enumerate((0,3,1,4,2,5)): assert mt[i] == val
Example #21
Source File: test_array.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_matmul(): # 1 3 # 2 4 m = robjects.r.matrix(robjects.IntVector(range(1, 5)), nrow=2) # 1*1+3*2 1*3+3*4 # 2*1+4*2 2*3+4*4 m2 = m @ m for i,val in enumerate((7.0, 10.0, 15.0, 22.0,)): assert m2[i] == val
Example #22
Source File: test_array.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_crossprod(): m = robjects.r.matrix(robjects.IntVector(range(4)), nrow=2) mcp = m.crossprod(m) for i,val in enumerate((1.0,3.0,3.0,13.0,)): assert mcp[i] == val
Example #23
Source File: test_array.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_tcrossprod(): m = robjects.r.matrix(robjects.IntVector(range(4)), nrow=2) mtcp = m.tcrossprod(m) for i,val in enumerate((4,6,6,10,)): assert mtcp[i] == val
Example #24
Source File: test_array.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_eigen(): m = robjects.r.matrix(robjects.IntVector((1, -1, -1, 1)), nrow=2) res = m.eigen() for i, val in enumerate(res.rx2("values")): assert (2, 0)[i] == val
Example #25
Source File: test_array.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_dot(): m = robjects.r.matrix(robjects.IntVector(range(4)), nrow=2, ncol=2) m2 = m.dot(m) assert tuple(m2) == (2,3,6,11)
Example #26
Source File: test_array.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_colnames(): m = robjects.r.matrix(robjects.IntVector(range(4)), nrow=2, ncol=2) assert m.colnames == rinterface.NULL m.colnames = robjects.StrVector(('a', 'b')) assert len(m.colnames) == 2 assert m.colnames[0] == 'a' assert m.colnames[1] == 'b' with pytest.raises(ValueError): m.colnames = robjects.StrVector(('a', 'b', 'c'))
Example #27
Source File: test_array.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_rownames(): m = robjects.r.matrix(robjects.IntVector(range(4)), nrow=2, ncol=2) assert m.rownames == rinterface.NULL m.rownames = robjects.StrVector(('c', 'd')) assert len(m.rownames) == 2 assert m.rownames[0] == 'c' assert m.rownames[1] == 'd' with pytest.raises(ValueError): m.rownames = robjects.StrVector(('a', 'b', 'c'))
Example #28
Source File: test_robjects.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_items(): v = robjects.IntVector((1,2,3)) rs = robjects.robject.RSlots(v) assert len(tuple(rs.items())) == 0 v.do_slot_assign('a', robjects.IntVector((9,))) for ((k_o,v_o), (k,v)) in zip((('a', robjects.IntVector), ), rs.items()): assert k_o == k assert v_o == type(v)
Example #29
Source File: test_packages.py From rpy2 with GNU General Public License v2.0 | 5 votes |
def test_new_with_dot_conflict(self): env = robjects.Environment() env['a.a_a'] = robjects.StrVector('abcd') env['a_a.a'] = robjects.IntVector((1,2,3)) env['c'] = robjects.r(''' function(x) x^2''') with pytest.raises(packages.LibraryError): robjects.packages.Package(env, "dummy_package")
Example #30
Source File: RComparisonBase.py From tbats with MIT License | 5 votes |
def r_bats(self, y, components): components = components.copy() if 'seasonal_periods' in components: components['seasonal_periods'] = ro.IntVector(components['seasonal_periods']) importr('forecast') r_bats_func = ro.r['bats'] r_forecast = ro.r['forecast'] r_y = ro.FloatVector(list(y)) r_model = r_bats_func(r_y, **components) summary = r_forecast(r_model) # predictions = np.array(summary.rx('fitted')).flatten() return summary, r_model