R 실습환경 구축하기
https://www.r-project.org/
https://www.rstudio.com/ 알스튜디오를 사용해야 생산성을 향상시킬 수 있다.
설치방법 참조
https://iamoverthemoon.tistory.com/64
** 자바 기반 R관련 package 를 사용하기 위한 설정 **
>Sys.setenv(JAVA_HOME="c:/program files/java/jre~")
>Sys.getenv() <== R 환경설정 정보 확인
R 버전업 하기
install.packages("installr")
library(installr)
install.R() # R 버전업
R.version # R버전확인
RStudio를 껏다 켬
many R packages and projects https://www.rstudio.com/products/rpackages/
많이 사용되는 패키지 https://3months.tistory.com/291
도서명 : 통계학의 이해(R 적용)
R datasets파일 다운로드 https://vincentarelbundock.github.io/Rdatasets/datasets.html
R컴파일 도구(Rtools) - 윈도우 용 https://cran.r-project.org/bin/windows/Rtools/
** Centos(Linux)에 R 설치하기 **
R 설치
[root@localhost ~]# yum install epel-release <== epel은 유용한 유틸리티가 많이 포함된 필수 추가 리파지토리임.
참고 : Centos8일 때 아래 # yum install R 명령을 수행하지 못하고 에러가 발생하는 경우
[root@localhost ~]# yum install dnf-plugins-core
[root@localhost ~]# yum config-manager --set-enabled powertools
[root@localhost ~]# yum install R
[root@localhost ~]# R
Rstudio 설치
[root@localhost ~]# wget https://download1.rstudio.org/desktop/fedora28/x86_64/rstudio-1.2.5033-x86_64.rpm
[root@localhost ~]# rpm -ivh rstudio-1.2.5033-x86_64.rpm
[root@localhost ~]# exit
[test@localhost ~]$ rstudio
* 혹시 실행이 안되면 터미널 창을 종료 후 다시 실행 시켜보자.
--- R-studio 단축키 ------------------------
ctrl + enter : script 현재 행 실행
ctrl + shift + enter : script 모든 행 실행
ctrl + alt + r : script 모든 행 실행
ctrl + alt + b : 처음부터 현재 행까지 실행
ctrl + alt + e : 현재 행부터 마지막까지 실행
Tab key : Assist 기능
ctrl + + :화면 확대
ctrl + - :화면 축소
ctrl + f : 찾기 또는 바꾸기
alt + - : <- 가 자동완성
-----------------------------------
참고 : R Server 구축 - hosting
* R service 설정
[root@localhost ~]# vi /etc/selinux/config
SELINUX=permissive <= 이걸로 변경 후 reboot 해준다.
[root@localhost ~]# cd /usr/lib/firewalld/services/
[root@localhost services]# cp http.xml R.xml
[root@localhost services]# vi R.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>R</short>
<description></description>
<port protocol="tcp" port="8787"/>
</service>
[root@localhost services]# firewall-cmd --permanent --zone=public --add-service=R
[root@localhost services]# firewall-cmd --reload
* R server 설치
참조 : https://www.rstudio.com/products/rstudio/download-server/
신 버전을 원한다면 위의 페이지에서 파일명만 새로운 것으로 하여 아래의 wget을 진행하자.
구버전
[root@localhost ~]# wget https://download2.rstudio.org/server/fedora28/x86_64/rstudio-server-rhel-1.2.5033-x86_64.rpm
[root@localhost ~]# yum install --nogpgcheck rstudio-server-rhel-1.2.5033-x86_64.rpm
[root@localhost ~]# systemctl status rstudio-server
[root@localhost ~]# systemctl start rstudio-server
2021년 9월 현재
[root@localhost ~]# wget https://download2.rstudio.org/server/centos8/x86_64/rstudio-server-rhel-1.4.1717-x86_64.rpm
[root@localhost ~]# yum install rstudio-server-rhel-1.4.1717-x86_64.rpm
[root@localhost ~]# systemctl status rstudio-server
[root@localhost ~]# systemctl start rstudio-server
참고 : start, stop, status
원격으로 R server 로그인 하기
ip 확인은 ~# ip addr
원격접속이 가능한 컴에서 http://ip:8787/auth-sign-in
하고 리눅스 username : 리눅스계정명 password : 암호 를 입력하면 Rstudio가 실행된다.
연습용 R source, 리눅스의 해당 계정에 kbs 디렉토리를 만들자.
dataframe <- c(1,2,3,4,5,6,7,8,9,10)
sample(x=dataframe)
df <- data.frame(eng=c(90,80), mat=c(100,88), class=c(1,2))
df
save(df, file = "kbs/df1.rda")
rm(df)
df
load("kbs/df1.rda")
df
참고로 내부 네트웍 기반의 실습실(VMWARE 사용)에서 다른 컴으로 로그인을 시도할 경우 Connection connection을 NAT에서 Bridged로 변경(VMware 기준)해 줄 상황이 발생할 수도 있다.
카페 http://cafe.daum.net/flowlife/RZ23/11 참조.