> For the complete documentation index, see [llms.txt](https://sugiaki1989.gitbook.io/r-for-data-science-answers/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sugiaki1989.gitbook.io/r-for-data-science-answers/chapter04-script.md).

# 4章 ワークフロー：スクリプト

### 4.1 コードを実行する

{% hint style="info" %}
練習問題はありません
{% endhint %}

### 4.2 Rstudioの診断

#### 練習問題1 : RStudio Tipsの面白いと思われるヒントを見つけなさい。

[RStudio Tips](https://twitter.com/rstudiotips)はRに関する役立つ情報をつぶやくTwitterアカウントです。フォローしてみて、面白い、役立つヒントを見つけてください。

![](/files/-Lh5rJgnYZHzSHjUb88Y)

#### 練習問題2 : RStudioの診断機能は下記以外にどんな間違いを見つけてくれるのか調べなさい。

[RStuidoのコード診断](https://support.rstudio.com/hc/en-us/articles/205753617-Code-Diagnostics)のページに詳細が記載されておりますので、そちらも合わせて確認してください。

* **R関数呼び出しの引数を確認する**

例えば、​​RStudioは関数`add_numbers`に`y`引数がないことを検出します。

![](/files/-Lh5sPokHY2-hJk9cfKX)

同様に、引数が欠落している、欠落しているコンマなどを検出してくれます。

![](/files/-Lh5s_g9tJQg9BDOvcMV)

* **使用されている変数のスコープ内に定義がない場合に警告する**

現在、または親のスコープ内で定義なしでシンボルが使用されている場合は警告します。シンボルの名前にタイプミスがあると思われる場合は、診断エンジンが提案を出します。

![](/files/-Lh5sja8BhBqTN2qgXR3)

* **変数が定義されているが使用されていない場合は警告する**

この診断は、変数が作成されたが使用されていないことを識別するのに役立ちます。これは古いコードをクリーンアップしようとしたり、他のエラーを診断するのに役立ちます。次の例では、変数`result`に代入されていますが、使用されていません。代わりに、合計が再計算されてから返されています。そのため、警告がひょうじされます。&#x20;

![](/files/-Lh5sqrH2XJl4c3Nsj3G)

* **Rスタイルの診断を提供します（例：空白）**

スタイル診断は、コードが[Hadley Wickhamのスタイルガイド](http://adv-r.had.co.nz/Style.html)に準拠しているかどうかを確認し、スタイルの警告を報告します。特に、診断エンジンは、空白の不適切な使用を検出します。

![](/files/-Lh5svp5hn0JFO7F2Ify)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sugiaki1989.gitbook.io/r-for-data-science-answers/chapter04-script.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
