以下を試したがダメだった!
%load_ext rpy2.ipython
r('sessionInfo()')
R version 3.2.4 Revised (2016-03-16 r70336) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 14.04.5 LTS locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets methods base
%R X=c(1,4,5,7); sd(X); mean(X)
RRuntimeErrorTraceback (most recent call last) <ipython-input-9-de588f5c5b3c> in <module>() ----> 1 get_ipython().magic(u'R X=c(1,4,5,7); sd(X); mean(X)') /usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s) 2161 magic_name, _, magic_arg_s = arg_s.partition(' ') 2162 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) -> 2163 return self.run_line_magic(magic_name, magic_arg_s) 2164 2165 #------------------------------------------------------------------------- /usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line) 2082 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals 2083 with self.builtin_trap: -> 2084 result = fn(*args,**kwargs) 2085 return result 2086 <decorator-gen-134> in R(self, line, cell, local_ns) /usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k) 191 # but it's overkill for just that one bit of state. 192 def magic_deco(arg): --> 193 call = lambda f, *a, **k: f(*a, **k) 194 195 if callable(arg): /usr/lib/sagemath/local/lib/python2.7/site-packages/rpy2-2.8.1-py2.7-linux-x86_64.egg/rpy2/ipython/rmagic.py in R(self, line, cell, local_ns) 663 ro.r.assign(input, localconverter.py2ri(val)) 664 --> 665 tmpd = self.setup_graphics(args) 666 667 text_output = '' /usr/lib/sagemath/local/lib/python2.7/site-packages/rpy2-2.8.1-py2.7-linux-x86_64.egg/rpy2/ipython/rmagic.py in setup_graphics(self, args) 413 # Note: that %% is to pass into R for interpolation there 414 ro.r.png("%s/Rplots%%03d.png" % tmpd_fix_slashes, --> 415 **argdict) 416 elif self.device == 'svg': 417 self.cairo.CairoSVG("%s/Rplot.svg" % tmpd_fix_slashes, /usr/lib/sagemath/local/lib/python2.7/site-packages/rpy2-2.8.1-py2.7-linux-x86_64.egg/rpy2/robjects/functions.py in __call__(self, *args, **kwargs) 176 v = kwargs.pop(k) 177 kwargs[r_k] = v --> 178 return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs) 179 180 pattern_link = re.compile(r'\\link\{(.+?)\}') /usr/lib/sagemath/local/lib/python2.7/site-packages/rpy2-2.8.1-py2.7-linux-x86_64.egg/rpy2/robjects/functions.py in __call__(self, *args, **kwargs) 104 for k, v in kwargs.items(): 105 new_kwargs[k] = conversion.py2ri(v) --> 106 res = super(Function, self).__call__(*new_args, **new_kwargs) 107 res = conversion.ri2ro(res) 108 return res RRuntimeError: Error in .External2(C_X11, paste("png::", filename, sep = ""), g$width, : unable to start device PNG
%%R
library(datasets)
png("test.png", width=1200, height=1200, units="px", type="cairo")
boxplot(mpg~cyl,data=mtcars, main="Car Milage Data", xlab="Number of Cylinders", ylab="Miles Per Gallon")
dev.off()
RRuntimeErrorTraceback (most recent call last) <ipython-input-10-0bf88fa07b3b> in <module>() ----> 1 get_ipython().run_cell_magic(u'R', u'', u'library(datasets)\npng("test.png", width=1200, height=1200, units="px", type="cairo")\nboxplot(mpg~cyl,data=mtcars, main="Car Milage Data", xlab="Number of Cylinders", ylab="Miles Per Gallon")\ndev.off()') /usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_cell_magic(self, magic_name, line, cell) 2118 magic_arg_s = self.var_expand(line, stack_depth) 2119 with self.builtin_trap: -> 2120 result = fn(magic_arg_s, cell) 2121 return result 2122 <decorator-gen-134> in R(self, line, cell, local_ns) /usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k) 191 # but it's overkill for just that one bit of state. 192 def magic_deco(arg): --> 193 call = lambda f, *a, **k: f(*a, **k) 194 195 if callable(arg): /usr/lib/sagemath/local/lib/python2.7/site-packages/rpy2-2.8.1-py2.7-linux-x86_64.egg/rpy2/ipython/rmagic.py in R(self, line, cell, local_ns) 663 ro.r.assign(input, localconverter.py2ri(val)) 664 --> 665 tmpd = self.setup_graphics(args) 666 667 text_output = '' /usr/lib/sagemath/local/lib/python2.7/site-packages/rpy2-2.8.1-py2.7-linux-x86_64.egg/rpy2/ipython/rmagic.py in setup_graphics(self, args) 413 # Note: that %% is to pass into R for interpolation there 414 ro.r.png("%s/Rplots%%03d.png" % tmpd_fix_slashes, --> 415 **argdict) 416 elif self.device == 'svg': 417 self.cairo.CairoSVG("%s/Rplot.svg" % tmpd_fix_slashes, /usr/lib/sagemath/local/lib/python2.7/site-packages/rpy2-2.8.1-py2.7-linux-x86_64.egg/rpy2/robjects/functions.py in __call__(self, *args, **kwargs) 176 v = kwargs.pop(k) 177 kwargs[r_k] = v --> 178 return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs) 179 180 pattern_link = re.compile(r'\\link\{(.+?)\}') /usr/lib/sagemath/local/lib/python2.7/site-packages/rpy2-2.8.1-py2.7-linux-x86_64.egg/rpy2/robjects/functions.py in __call__(self, *args, **kwargs) 104 for k, v in kwargs.items(): 105 new_kwargs[k] = conversion.py2ri(v) --> 106 res = super(Function, self).__call__(*new_args, **new_kwargs) 107 res = conversion.ri2ro(res) 108 return res RRuntimeError: Error in .External2(C_X11, paste("png::", filename, sep = ""), g$width, : unable to start device PNG