> For the complete documentation index, see [llms.txt](https://docs.bcbi.brown.edu/codiac-for-health/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bcbi.brown.edu/codiac-for-health/computing/r/basic-syntax.md).

# Basic Syntax

## "Hello, World!" Program

This is the typical first program for those new to a programming language. It can be used to test that the [**Installation**](https://docs.bcbi.brown.edu/codiac-for-health/computing/r/installation) of R is working and also introduce R's basic syntax using the [**REPL**](https://docs.bcbi.brown.edu/codiac-for-health/computing/r/repl) environment or running code written using a [**Text Editor**](https://docs.bcbi.brown.edu/codiac-for-health/computing/text-editors) at the [**Unix**](https://docs.bcbi.brown.edu/codiac-for-health/computing/unix) command line.

#### Inputs:

```r
#This is a single line comment
print("Hello, World!")
```

#### Outputs:

```r
"Hello, World!"
```

## Variable Assignment

| Operator       | Description      | Example                |
| -------------- | ---------------- | ---------------------- |
| <- or = or <<- | Left Assignment  | x <- 7, x = 7, x <<- 7 |
| -> or ->>      | Right Assignment | x -> 7, x ->> 7        |

## Vectors (Classes)

| Type      | Example         |
| --------- | --------------- |
| Logical   | TRUE, FALSE     |
| Numeric   | 1, 55, 999      |
| Integer   | 1L, 32L, 0L     |
| Complex   | 2 + 3i          |
| Character | "great", "23.4" |

## Print Statements

Unlike other languages, R does not require the use of print statements to output code, but it does allow them. To print, you can simply write code, or include the code you want to be printed in a print() statement.

### Vector Assignment and Print Statement examples:

#### Inputs:

```r
#Assign three colors to the "apple" variable
apple <- c('red','green','yellow')

print(apple)

#Get the class of the vector (with and without print statement)
print(class(apple))
class(apple)
```

#### Outputs:

```r
"red"  "green"  "yellow"
"character"
"character"
```

## Comments

We can write comments on our code, which do not run, to describe what certain lines of code or section of code do. These comments are just for the programmer- they will not appear anywhere in the output and simply explain what the code is doing or provide helpful notes.

* To comment in R, use the “#” symbol and type your comment on the same line
* R has no syntax for multi-line comments, so each line that is commented out needs a "#" symbol at the beginning

## Resources

* R Documentation: [Vectors and Assignment](https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Vectors-and-assignment)
* R Documentation:[ Comments](https://cran.r-project.org/doc/manuals/r-release/R-intro.html#R-commands_003b-case-sensitivity-etc)


---

# 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://docs.bcbi.brown.edu/codiac-for-health/computing/r/basic-syntax.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.
