Title: | Importing and Exporting SPSS Files |
---|---|
Description: | Package to read and write the SPSS file formats. |
Authors: | Jan Marvin Garbuszus [aut, cre], Ben Pfaff [aut, cph] (author of encryption part), Jeroen Ooms [ctr], readstata13 [cph], R Core Team [cph], Ulrich Poetter [ctb], Goetz Rohwer [cph] |
Maintainer: | Jan Marvin Garbuszus <[email protected]> |
License: | GPL-2 | file LICENSE |
Version: | 0.17.1 |
Built: | 2024-11-16 04:51:46 UTC |
Source: | https://github.com/JanMarvin/readspss |
Function to read a SPSS por file into a data.frame().
read.por( file, convert.factors = TRUE, generate.factors = TRUE, encoding = TRUE, fromEncoding = NULL, use.missings = TRUE, debug = FALSE, override = FALSE, convert.dates = TRUE, add.rownames = FALSE )
read.por( file, convert.factors = TRUE, generate.factors = TRUE, encoding = TRUE, fromEncoding = NULL, use.missings = TRUE, debug = FALSE, override = FALSE, convert.dates = TRUE, add.rownames = FALSE )
file |
string a por-file to import. can be a file on a computer or an url. in this case the file will be downloaded and read before it is used. |
convert.factors |
logical if true numeric or character variables will be converted into a factor in R. |
generate.factors |
logical function to convert variables with
partial labels into factors. e.g. 1 - low and 5 - high are provided, labels
2, 3 and 4 will be created. especially useful in combination with
|
encoding |
logical shall values be converted? If true, |
fromEncoding |
character encoding of the imported file. This information is stored inside the por-file, but is currently unused. Still this option can be used to define the initial encoding by hand. |
use.missings |
logical should missing values be converted. Defaults to TRUE. |
debug |
logical provides additional debug information. Most likely not useful to any user. |
override |
logical The filename provided in |
convert.dates |
logical Should dates be converted on the fly? |
add.rownames |
logical If |
SPSS files are widely available, though for R long time only foreign and memisc provided functions to import por-files. Lately haven joined. This package is an approach to offer another alternative, to document the por-format and provide additional options to import the data.
Information to decrypt the por-format was provided by tda www.stat.rub.de/tda.html and pspp www.gnu.org/software/pspp/
read.spss
, memisc
.
Function to read a SPSS sav file into a data.frame().
read.sav( file, convert.factors = TRUE, generate.factors = TRUE, encoding = TRUE, fromEncoding = NULL, use.missings = TRUE, debug = FALSE, override = FALSE, convert.dates = TRUE, add.rownames = FALSE, pass )
read.sav( file, convert.factors = TRUE, generate.factors = TRUE, encoding = TRUE, fromEncoding = NULL, use.missings = TRUE, debug = FALSE, override = FALSE, convert.dates = TRUE, add.rownames = FALSE, pass )
file |
string a sav-file to import. can be a file on a computer or an url. in this case the file will be downloaded and read before it is used. |
convert.factors |
logical if true numeric or character variables will be converted into a factor in R. |
generate.factors |
logical function to convert variables with
partial labels into factors. e.g. 1 - low and 5 - high are provided, labels
2, 3 and 4 will be created. especially useful in combination with
|
encoding |
logical shall values be converted? If true, read.sav will try the charcode stored inside the sav-file. If this value is 2 or not available, fromEncoding can be used to change encoding. |
fromEncoding |
character. encoding of the imported file. This information is stored inside the sav-file, but is currently unused. Still this option can be used to define the initial encoding by hand. |
use.missings |
logical should missing values be converted. Defaults to TRUE. |
debug |
logical provides additional debug information. Most likely not useful to any user. |
override |
logical. The filename provided in |
convert.dates |
logical. Should dates be converted on the fly? |
add.rownames |
logical. If |
pass |
character. If encrypted sav should be imported, this is a maximum of ten character encryption key. |
SPSS files are widely available, though for R long time only foreign and memisc provided functions to import sav-files. Lately haven joined. This package is an approach to offer another alternative, to document the sav-format and provide additional options to import the data. sav-files are stored most exclusively as numerics only in compression mode are some integers stored as integers. Still they are returned as numerics.
readspss
returns a data.frame with additional attributes
row.names rownames
names colnames
datalabel datalabel
datestamp datestamp
timestamp timestamp
filelabel filelabel
class data.frame
vtype SPSS type 0 is usually a numeric/integer
disppar matrix of display parameters if available
missings a list containing information about the missing variables. if
use.missings=TRUE
this Information will be used to generate missings.
haslabel list of variables that contain labels
longstring character vector of long strings if any in file
longmissing character vector of missings in longstrings if any
longlabel character vector of long labels
cflag 0 if uncompressed, 1 if compressed
endian 2 or 3 if little endian else 0
compression compression similar to cflag, somehow stored twice in the sav file
doc list containing documentation information if any
charcode encoding string most likely 2 is CP1252
encoding sometimes sav-file contain encoding as a extra string
ownEnc encoding of the R-session
doenc was the file supposed to be encoded?
autoenc was encoding applied to the file?
swapit were the bytes swapped?
totals character string of totals if any
dataview xml file how the data should be printed
extraproduct additional string provided
label list containing label value information
varmatrix a matrix with information how the data is stored
var.label variable labels
lmissings missings table if any in longstrings
Information to decrypt the sav-format was provided by tda www.stat.rub.de/tda.html and pspp www.gnu.org/software/pspp/
read.spss
, memisc
and
read_sav
.
fl <- system.file("extdata", "electric.sav", package = "readspss") dd <- read.sav(fl)
fl <- system.file("extdata", "electric.sav", package = "readspss") dd <- read.sav(fl)
Function to read a SPSS (z)sav or por file into a data.frame(). This is just a wrapper around read.sav and read.por for convenience.
read.spss(x, ...)
read.spss(x, ...)
x |
file to import |
... |
additional arguments passed to read.sav or read.por please see the documentation for these functions. |
Function to write an SPSS por file. Returns an por file that read.por can read as well as SPSS can. Other packages as foreign, memisc and haven might fail (fail reading or return wrong values).
write.por( dat, filepath, label, add.rownames = FALSE, convert.factors = TRUE, toEncoding = "CP1252", convert.dates = TRUE, tz = "GMT" )
write.por( dat, filepath, label, add.rownames = FALSE, convert.factors = TRUE, toEncoding = "CP1252", convert.dates = TRUE, tz = "GMT" )
dat |
data.frame a data.frame to export as por-file. |
filepath |
string full path where and how this file should be stored |
label |
character vector of labels. must be of size |
add.rownames |
logical If |
convert.factors |
logical If |
toEncoding |
character encoding used for the por file. SPSS itself claims to have problems with unicode and por files, so "CP1252" is the default. |
convert.dates |
logical should dates be converted to SPSS format |
tz |
character The name of the timezone convert.dates will use. |
Strings longer than 255 chars are not provided. File will be stored using "CP1252" encoding.
write.por
returns nothing
Function to write an SPSS sav or zsav file from a data.frame().
write.sav( dat, filepath, label, add.rownames = FALSE, compress = FALSE, convert.dates = TRUE, tz = "GMT", debug = FALSE, is_zsav = FALSE, disppar )
write.sav( dat, filepath, label, add.rownames = FALSE, compress = FALSE, convert.dates = TRUE, tz = "GMT", debug = FALSE, is_zsav = FALSE, disppar )
dat |
data.frame a data.frame to store as SPSS file. |
filepath |
string full path where and how this file should be stored |
label |
character if any provided this must be a vector of
labels. It must be of size |
add.rownames |
logical If |
compress |
logical should compression be used. If TRUE some integers will be stored more efficiently. Everything will be stored in chunks of 8 chars. Reduces memory size of sav-file. |
convert.dates |
logical should dates be converted to SPSS format. |
tz |
character The name of the timezone convert.dates will use. |
debug |
logical print debug information. |
is_zsav |
logical explicitly create a zsav file. If the file ending zsav is used, this is selected as default. |
disppar |
optional display parameter matrix. Needs documentation. |
Writing of strings longer than 255 chars is not provided.
write.sav
returns nothing