Skip to contents

If you do not have a grid program at hand you can define a grid using a standard text editor and by saving it as a .txt file. The .txt file has to be in a fixed format. There are three mandatory blocks each starting and ending with a predefined tag in uppercase letters. The first block starts with ELEMENTS and ends with END ELEMENTS and contains one element in each line. The other mandatory blocks contain the constructs and ratings (see below). In the block containing the constructs the left and right pole are separated by a colon (:). To define missing values use NA like in the example below. One optional block contains the range of the rating scale used defined by two numbers. The order of the blocks is arbitrary. All text not contained within the blocks is discarded and can thus be used for comments.

Usage

importTxt(file, dir = NULL, min = NULL, max = NULL)

Arguments

file

A vector of filenames including the full path if file is not in current working directory. File can also be a complete URL. The file suffix has to be .txt.

dir

Alternative way to supply the directory where the file is located (default NULL).

min

Optional argument (numeric, default NULL) for minimum rating value in grid.

max

Optional argument (numeric, default NULL) for maximum rating value in grid.

Value

A single repgrid object in case one file and a list of repgrid objects in case multiple files are imported.

Details

---------------- .txt file -----------------
anything not contained within the tags will be discarded
ELEMENTS
element 1
element 2
element 3
END ELEMENTS
CONSTRUCTS
left pole 1 : right pole 1
left pole 2 : right pole 2
left pole 3 : right pole 3
left pole 4 : right pole 4
END CONSTRUCTS
RATINGS
1 3 2
4 1 1
1 4 4
3 1 1
END RATINGS
RANGE
1 4
END RANGE
---------------- end of file ----------------

Note that the maximum and minimum value has to be defined using the min and max arguments if no RANGE block is contained in the data file. Otherwise the scaling range is inferred from the available data and a warning is issued as the range may be erroneous. This may effect other functions that depend on knowing the correct range and it is thus strongly recommended to set the scale range correctly.

Examples

if (FALSE) {

# supposing that the data file sample.txt is in the current directory
file <- "sample.txt"
rg <- importTxt(file)

# specifying a directory (arbitrary example directory)
dir <- "/Users/markheckmann/data"
rg <- importTxt(file, dir)

# using a full path
rg <- importTxt("/Users/markheckmann/data/sample.txt")

# importing more than one .txt file via R code
files <- c("sample.txt", "sample_2.txt")
rg <- importTxt(files)
}