

   tempfile {base}                              R Documentation

   CCrreeaattee UUnniiqquuee NNaammeess ffoorr ((TTeemmppoorraarryy)) FFiilleess

   UUssaaggee::

        tempfile(pattern = "file")

   AArrgguummeennttss::

    pattern: a character vector giving the initial part of the
             name.

   VVaalluuee::

        A character vector giving the names of possible (tempo-
        rary) files.  The names are guaranteed to be unique
        among calls to `tempfile' in an R session.  Note that
        no files are generated by `tempfile'.

   SSeeee AAllssoo::

        `unlink' for deleting files.

   EExxaammpplleess::

        ## One possibility of getting ALL environment variables;
        ## compare with `getenv':
        fun <- function() {
          FILE <- tempfile("fun")
          on.exit(unlink(FILE))
          system(paste("printenv >", FILE))
          x <- strsplit(scan(FILE, what = ""), "=")
          v <- n <- character(LEN <- length(x))
          for (i in 1:LEN) {
            n[i] <- x[[i]][1]
            v[i] <- paste(x[[i]][-1], collapse = "=")
          }
          structure(v, names = n)
        }

        fun()

