如何从R脚本调用linux终端代码

时间:2017-05-29 06:13:45

标签: r linux system-calls

我的问题是:

如何在 R脚本中调用Linux终端?

我知道这可能是一个愚蠢的问题...我的R代码在这里:

download.file('https://some.dir,
              destfile = '/home/myfile.grb2',method='auto',quiet = FALSE,
              mode="wb", cacheOK = TRUE)

下载后,我不得不使用终端代码转换该文件...但我需要这是自动的。转换器代码是这样的:

source activate ncl_stable
cd /home
ncl_convert2nc myfile.grb2

谷歌搜索我看到 Linux终端使用 C ++ 。我知道有一个包运行C ++代码到R, Rcpp ,但它的工作方式与Linux终端类似吗?

1 个答案:

答案 0 :(得分:1)

这样可以解决问题:

rgbImage = imread('JjkrL.jpg') ;
%% Remove the white background
grayImage = min(rgbImage, [], 3);
binaryImage = grayImage < 200;
binaryImage = bwareafilt(binaryImage, 1);
[rows, columns] = find(binaryImage);
row1 = min(rows);
row2 = max(rows);
col1 = min(columns);
col2 = max(columns);
% Crop
croppedImage = rgbImage(row1:row2, col1:col2, :);
[nx,ny,t] = size(croppedImage) ;
imshow(croppedImage) ;
%%
% Centers of circles
C1 = [84  142] ;
C2 = [76 136] ;

%% Get distances
% circle 1/ Big circle
% Edge points
top = [C1(1) 1] ;
bottom = [C1(1) nx] ;
left = [1 C1(2)] ;
right = [ny C1(2)] ;
pts = [top ;left ;bottom ; right] ;

hold on
plot(C1(1),C1(2),'*r')
plot(pts(:,1),pts(:,2),'*k') ;
%% Get distances
data = repmat(C1,[length(pts),1])-pts ;
dist = sqrt(data(:,1).^2+data(:,2).^2);

您可以找到更多信息herehere