Skip to contents

Extract or replace lines of Amiga Basic code

Usage

# S3 method for AmigaBasic
[(x, i)

# S3 method for AmigaBasic
[(x, i) <- value

# S3 method for AmigaBasic
[[(x, i)

# S3 method for AmigaBasic
[[(x, i) <- value

Arguments

x

An AmigaBasic class object from which specific lines need to be extracted or replaced.

i

In case of [[', an integer index, representing the line-number of basic code to be selected. In case of [': a vector of numeric indices. This index is used to select specific lines. Negative values will deselect lines.

value

A vector of character strings or an AmigaBasic() class object that is used to replace the selected indices i. value should represent the same number of lines of code as the selected number of lines.

Value

The extraction method returns an AmigaBasic() object based in the lines selected with i. The replacement method returns an AmigaBasic() object with the selected lines replaced with value.

Details

Extract or replace specific lines in an AmigaBasic()-class object.

Author

Pepijn de Vries

Examples

if (FALSE) {
## First generate a few lines of Basic code:
bas <- as.AmigaBasic(c(
  "LET a = 1",
  "a = a + 1",
  "PRINT \"a now equals\";a",
  "INPUT \"clear screen (y/n)? \", b$",
  "IF UCASE$(b$) = \"Y\" THEN CLS"
))

## Select only lines 4 and 5:
bas[4:5]

## use negative indices to deselect specific lines.
## deselect line 2:
bas[-2]

## replace line 2
bas[2] <- "a = a + 2"

## You can also use AmigaBasic class object as replacement
bas[2] <- as.AmigaBasic("a = a + 3")

## single lines can also be selected with '[['
bas[[2]]
}