dput
Read or Write a Text Representation of an object

Description

Creates and uses an ASCII file representing the object.

Usage

dput(x, file = "", control = c("keepNA", "keepInteger", 
   "showAttributes")) 
dget(file)

Arguments

x any object. Missing values (NAs) are allowed.
file a character string giving the file name where the data structure is to be stored and later retrieved. If the string is missing or empty, the value is printed on standard output.
control flags controlling the deparse of x. The valid argument is any combination of the following:
  • "all": All the other options should be selected except "delayPromises" and "S_compatible"
  • "keepInteger": Keep numeric value as integer rather than double.
  • "quoteExpressions": An expression is quoted and not evaluated.
  • "showAttributes": Displays the attributes of this object, if they are available.
  • "useSource": Prints out the source of a function definition rather than its body.
  • "warnIncomplete": Displays a warning for some special cases that object can't be fully deparsed.
  • "delayPromises": Delays promises.
  • "keepNA": Keeps NAs with their original type (that is, NA_integer_ and so on) and ensures they are deparsed to the same type.
  • "S_compatible": Is compatible with S.
See .deparseOpts for more details.

Details

Unlike the result for dump, the result of dput does not include the object name.
Value
dputreturns x invisibly.
dgetreturns the result of evaluating the content of file.
Side Effects
dput writes an ASCII version of the object onto the file. In particular, this file is suitable for moving between computers. If file is missing, the value is printed on standard output.
dget evaluates the content of file, so it can produce arbitrary side effects. However, if dput is used to produce the file, there should be no side effects.
Warning
The exact format of the object on the file is subject to change. You should regard these files as ASCII versions of assignments.
Note The exact equality of read-in numeric data cannot be guaranteed -- especially not across machines.
Differences between Spotfire Enterprise Runtime for R and Open-source R
See deparse for similar differences.
See Also
deparse, .deparseOpts, dump, source.
Examples
abc <- c("a", "b", "c")
dput(abc, "oldabc")  # store abc on file oldabc 
def <- dget("oldabc")  # read back in 

df <- data.frame(a = c(1.6, 3, NA, 5L), b = c("Red", "Green", "Blue", NA))

# default "control" is combination of "keepNA", # "keepInteger" and "showAttributes" dput(df)

dput(df, control = NULL) # remove all "control" options dput(df, control = "S_compatible")

# Create a function with comments baz <- function(x) { # Subtract from one 1-x } # and display it dput(baz) # and now display the saved source dput(baz, control = "useSource")

dput(as.environment(1), control = "warnIncomplete")

Package base version 6.1.4-13
Package Index