2020/08/15

Debian10(buster)にRをインストール

最終更新日: 2020/8/15

Debian10(buster)にRをインストールする手順を備忘録として残します。

実行環境


CPU
Intel(R) Core(TM) i5 CPU M450 @ 2.40GHz
Host OS
Windows10 Home 64bit
Guest OS
Debian10(buster) (VMware Workstation 15 Player)

参考URL


CRAN
 →"Download R for Linux"をクリック
 →"debian/"をクリック
 →"Debian Packages of R Software"
  "Last updated by Johannes Ranke on 2020-06-06"版を見ています。

インストール手順


"/etc/apt/sources.list"に以下の一文を追加する。

 deb http://cloud.r-project.org/bin/linux/debian buster-cran40/

"apt update"を実行する。

# apt update
ヒット:1 http://security.debian.org/debian-security buster/updates InRelease
ヒット:2 http://deb.debian.org/debian buster InRelease
ヒット:3 http://deb.debian.org/debian buster-updates InRelease
取得:4 http://cloud.r-project.org/bin/linux/debian buster-cran40/ InRelease [4,363 B]
エラー:4 http://cloud.r-project.org/bin/linux/debian buster-cran40/ InRelease
  公開鍵を利用できないため、以下の署名は検証できませんでした: NO_PUBKEY FCAE2A0E115C3D8A
hパッケージリストを読み込んでいます... 完了
W: GPG エラー: http://cloud.r-project.org/bin/linux/debian buster-cran40/ InRelease: 公開鍵を利用できないため、以下の署名は検証できませんでした: NO_PUBKEY FCAE2A0E115C3D8A
E: リポジトリ http://cloud.r-project.org/bin/linux/debian buster-cran40/ InRelease は署名されていません。
N: このようなリポジトリから更新を安全に行うことができないので、デフォルトでは更新が無効になっています。
N: リポジトリの作成とユーザ設定の詳細は、apt-secure(8) man ページを参照してください。

「公開鍵を利用できない」と言われてしまう。 解決策は参考URLの中ほどにある「Secure apt」の章を読むと分かる。

# apt-key adv --keyserver keys.gnupg.net --recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF'
E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation

上記のように「gnupgがない」と言われる場合はgnupgをインストールしてから実行する。

# apt install gnupg
# apt-key adv --keyserver keys.gnupg.net --recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF'
Executing: /tmp/apt-key-gpghome.bDdq0OQlVn/gpg.1.sh --keyserver keys.gnupg.net --recv-key E19F5F87128899B192B1A2C2AD5F960A256A04AF
gpg: 鍵AD5F960A256A04AF: 公開鍵"Johannes Ranke (Wissenschaftlicher Berater) <johannes.ranke@jrwb.de>"をインポートしました
gpg:           処理数の合計: 1
gpg:             インポート: 1
# apt update
ヒット:1 http://security.debian.org/debian-security buster/updates InRelease
ヒット:2 http://deb.debian.org/debian buster InRelease
ヒット:3 http://cloud.r-project.org/bin/linux/debian buster-cran40/ InRelease
取得:4 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
51.9 kB を 1秒 で取得しました (62.0 kB/s)
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
パッケージはすべて最新です。
#

無事に公開鍵がインストールできたようだ。最後に以下のコマンドを実行してRをインストールする。

# apt install -t buster-cran40 r-base

Rを起動してみる。

$ R

R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R は、自由なソフトウェアであり、「完全に無保証」です。
一定の条件に従えば、自由にこれを再配布することができます。
配布条件の詳細に関しては、'license()' あるいは 'licence()' と入力してください。

R は多くの貢献者による共同プロジェクトです。
詳しくは 'contributors()' と入力してください。
また、R や R のパッケージを出版物で引用する際の形式については
'citation()' と入力してください。

'demo()' と入力すればデモをみることができます。
'help()' とすればオンラインヘルプが出ます。
'help.start()' で HTML ブラウザによるヘルプがみられます。
'q()' と入力すれば R を終了します。

> q()
Save workspace image? [y/n/c]: n
$

無事にRが起動しました。

2020/03/31

円錐曲線(conic curve)の書き方

円錐曲線とは


出典: フリー百科事典『ウィキペディア(Wikipedia)

 円錐曲線(えんすいきょくせん、conic curve, conic section; 円錐断面)とは、円錐面を任意の平面で切断したときの断面としてえられる曲線群の総称である。


数式表現




\[ \begin{eqnarray} \left\{ \begin{array}{l} x = a \cos t \\ y = a \sin t \end{array} \right. \end{eqnarray} \tag{1} \label{1} \]

楕円


\[ \begin{eqnarray} \left\{ \begin{array}{l} x = a \cos t \\ y = b \sin t \end{array} \right. \end{eqnarray} \tag{2} \label{2} \]

放物線


\[ \displaystyle y = ax^2 + bx + c \tag{3} \label{3} \]

双曲線


\[ \begin{eqnarray} \left\{ \begin{array}{l} x = \pm a \cosh t \\ y = b \sinh t \end{array} \right. \end{eqnarray} \tag{4} \label{4} \]

書き方


 R言語での書き方は以下のとおり。



 条件: \(a=1\) の時

t=seq(0, 2*pi, length=180)
a=1
x=a*cos(t)
y=a*sin(t)
svg("archimedes.svg", width=5, height=5)
plot(x, y, type="l", asp=1, lwd=2, col=2)
abline(h=0)
abline(v=0)
dev.off()

楕円


 条件: \(a=3, b=2\) の時

t=seq(0, 2*pi, length=180)
a=3
b=2
x=a*cos(t)
y=b*sin(t)
svg("ellipse.svg", width=5, height=5)
plot(x, y, type="l", asp=1, lwd=2, col=2)
abline(h=0)
abline(v=0)
dev.off()

放物線


 条件: \(a=1, b=0, c=0\) の時

a=1
b=0
c=0
svg("parabola.svg", width=5, height=5)
curve(a*x^2+b*x+c, -2, 2, asp=1, lwd=2, col=2)
abline(h=0)
abline(v=0)
dev.off()

双曲線


 条件: \(a=1, b=1\) の時

a=1, b=1のとき
t=seq(-pi, pi, length=300)
a=b=1
x=a*cosh(t)
y=b*sinh(t)
svg("hyperbola.svg", width=5, height=5)
plot( x, y, type="l", asp=1, lwd=2, col=2, xlim=c(-15,15), ylim=c(-15,15), ann=F)
par(new=T)
plot(-x, y, type="l", asp=1, lwd=2, col=2, xlim=c(-15,15), ylim=c(-15,15))
abline(h=0)
abline(v=0)
dev.off()

2020/03/30

トラクトリックス(tractrix)の書き方

トラクトリックスとは


出典: フリー百科事典『ウィキペディア(Wikipedia)

 トラクトリックス (tractrix) は直交座標の方程式 \eqref{1} によって表される曲線である。


数式表現


\[ \begin{eqnarray} \displaystyle x &=& \log \frac{a \pm \sqrt {a^2 - y^2}}{y} \mp \sqrt {a^2 - y^2} \\ \displaystyle &=& a \cosh^{-1} (\frac{a}{y}) \mp \sqrt {a^2 - y^2} \tag{1} \label{1} \end{eqnarray} \]

書き方


 R言語での書き方は以下のとおり。

 条件: \(a=1\) の時

y=seq(0, 1, length=300)
a=1
x1=a*log((a+sqrt(a^2-y^2))/y)-sqrt(a^2-y^2)
x2=a*log((a-sqrt(a^2-y^2))/y)+sqrt(a^2-y^2)
svg("tractrix.svg", width=5, height=5)
plot(x1, y, type="l", asp=1, lwd=2, col=2, xlim=c(-2, 2), ylim=c(-2, 2), ann=F)
par(new=T)
plot(x2, y, type="l", asp=1, lwd=2, col=2, xlim=c(-2, 2), ylim=c(-2, 2), xlab="", ylab="")
abline(h=0)
abline(v=0)
dev.off()

【備忘録】時系列データの編集方法(R言語, tidyverse)

TimeSeries.knit 1 サンプルデータ作成 2 日付単位に集計する 2.1 月毎集計 2.2 四半期毎集計 ...