def test_from_int(): sexp = ri.vector([1, ], ri.RTYPES.INTSXP) isInteger = ri.globalenv.find('is.integer') assert isInteger(sexp)[0] with pytest.raises(ValueError): ri.vector(['a', ], ri.RTYPES.INTSXP)
def test_invalid_rtype(): with pytest.raises(ValueError): ri.vector([ 1, ], -1) with pytest.raises(ValueError): ri.vector([ 1, ], 250)
def test_from_bool(): sexp = ri.vector([True, ], ri.RTYPES.LGLSXP) isLogical = ri.globalenv.find('is.logical') assert isLogical(sexp)[0] assert sexp[0] is True sexp = ri.vector(['a', ], ri.RTYPES.LGLSXP) isLogical = ri.globalenv.find('is.logical') assert isLogical(sexp)[0] assert sexp[0]
def _run_without_initr(queue): import rpy2.rinterface as rinterface try: tmp = rinterface.vector([1, 2], rinterface.RTYPES.INTSXP) res = (True, None) except rinterface.embedded.RNotReadyError as re: res = (False, None) except Exception as e: res = (False, str(e)) queue.put(res)
def test_from_invalid_no_length(): s = (x for x in range(30)) with pytest.raises(TypeError): ri.vector(s, ri.RTYPES.INTSXP)
def test_invalid_not_vector_rtype(): with pytest.raises(ValueError): ri.vector([ 1, ], ri.RTYPES.ENVSXP)
def test_from_string(): sexp = ri.vector([ 'abc', ], ri.RTYPES.STRSXP) isCharacter = ri.globalenv.find('is.character') assert isCharacter(sexp)[0]
def test_from_complex(): sexp = ri.vector([ 1.0 + 1.0j, ], ri.RTYPES.CPLXSXP) isComplex = ri.globalenv.find('is.complex') assert isComplex(sexp)[0]
def test_from_float_nan(): with pytest.raises(ValueError): ri.vector([ "a", ], ri.RTYPES.REALSXP)
def test_from_float(): sexp = ri.vector([ 1.0, ], ri.RTYPES.REALSXP) isNumeric = ri.globalenv.find("is.numeric") assert isNumeric(sexp)[0]