

tempfile {base}                              R Documentation

_C_r_e_a_t_e _U_n_i_q_u_e _N_a_m_e_s _f_o_r _(_T_e_m_p_o_r_a_r_y_) _F_i_l_e_s

_U_s_a_g_e_:

     tempfile(pattern = "file")

_A_r_g_u_m_e_n_t_s_:

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

_V_a_l_u_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_e_e _A_l_s_o_:

     `unlink' for deleting files.

_E_x_a_m_p_l_e_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()

