[R] Vector of char generated by Sys.getenv function is not available when the package is loaded

Jose Claudio Faria joseclaudio.faria at gmail.com
Mon Sep 23 20:55:20 CEST 2013


I have been developing a new package (TinnRcom) to avoid the necessity
of any script
(as below) in the Rprofile.site file related to the use of Tinn-R Editor and R:

#===============================================================
# Tinn-R: necessary packages and functions
# Tinn-R: >= 2.4.1.1 with TinnR package >= 1.0.3
#===============================================================
# Set the URL of the preferred repository, below some examples:
options(repos='http://cran.at.r-project.org/')     # Austria/Wien
#options(repos='http://cran-r.c3sl.ufpr.br/')       # Brazil/PR
#options(repos='http://cran.fiocruz.br/')           # Brazil/RJ
#options(repos='http://www.vps.fmvz.usp.br/CRAN/')  # Brazil/SP
#options(repos='http://brieger.esalq.usp.br/CRAN/') # Brazil/SP

library(utils)

# Check necessary packages
necessary <- c('TinnR',
               'svSocket',
               'formatR')

installed <- necessary %in% installed.packages()[, 'Package']
if (length(necessary[!installed]) >=1)
  install.packages(necessary[!installed])

# Load packages
library(TinnR)
library(svSocket)

# Uncoment the two lines below if you want Tinn-R to always start R at start-up
# (Observation: check the path of Tinn-R.exe)
options(IDE='C:/Tinn-R/bin/Tinn-R.exe')
trStartIDE()

# Short paths
.trPaths <- paste(paste(Sys.getenv('APPDATA'),
                        '\\Tinn-R\\tmp\\',
                        sep=''),
                  c('',
                    'search.txt',
                    'objects.txt',
                    'file.r',
                    'selection.r',
                    'block.r',
                    'lines.r',
                    'reformat-input.r',
                    'reformat-output.r'),
                  sep='')

library(Matrix)
library(cluster)
library(Hmisc)
#===============================================================

For this it is necessary to put the object trPaths in the new TinnRcom package.

I make this as follows in the folder TinnRcom/R/trPaths.R:

trPaths <- paste(paste(Sys.getenv('APPDATA'),
                       '\\Tinn-R\\tmp\\',
                       sep=''),
                 c('',
                   'search.txt',
                   'objects.txt',
                   'file.r',
                   'selection.r',
                   'block.r',
                   'lines.r',
                   'reformat-input.r',
                   'reformat-output.r'),
                 sep='')


The NAMESPACE file is as below:

import(utils, tcltk, Hmisc, R2HTML)
importFrom(formatR, tidy.source)
importFrom(svSocket, evalServer)

export(
  trArgs,
  trComplete,
  trCopy,
  trExport,
  trObjList,
  trObjSearch,
  trPaths,
  trStartIDE)

S3method(trExport, default)
S3method(trExport, data.frame)
S3method(trExport, matrix)


After to load the package

> library(TinnRcom)

the result is always:
> trPaths
[1] "\\Tinn-R\\tmp\\"                  "\\Tinn-R\\tmp\\search.txt"
[3] "\\Tinn-R\\tmp\\objects.txt"       "\\Tinn-R\\tmp\\file.r"
[5] "\\Tinn-R\\tmp\\selection.r"       "\\Tinn-R\\tmp\\block.r"
[7] "\\Tinn-R\\tmp\\lines.r"           "\\Tinn-R\\tmp\\reformat-input.r"
[9] "\\Tinn-R\\tmp\\reformat-output.r"

When should be:
> trPaths
[1] "C:\\Users\\jcfaria\\AppData\\Roaming\\Tinn-R\\tmp\\"
[2] "C:\\Users\\jcfaria\\AppData\\Roaming\\Tinn-R\\tmp\\search.txt"
[3] "C:\\Users\\jcfaria\\AppData\\Roaming\\Tinn-R\\tmp\\objects.txt"
[4] "C:\\Users\\jcfaria\\AppData\\Roaming\\Tinn-R\\tmp\\file.r"
[5] "C:\\Users\\jcfaria\\AppData\\Roaming\\Tinn-R\\tmp\\selection.r"
[6] "C:\\Users\\jcfaria\\AppData\\Roaming\\Tinn-R\\tmp\\block.r"
[7] "C:\\Users\\jcfaria\\AppData\\Roaming\\Tinn-R\\tmp\\lines.r"
[8] "C:\\Users\\jcfaria\\AppData\\Roaming\\Tinn-R\\tmp\\reformat-input.r"
[9] "C:\\Users\\jcfaria\\AppData\\Roaming\\Tinn-R\\tmp\\reformat-output.r"

What is wrong?
Why the Sys.getenv function is not making the job when in the package?

Anyone can help please?

P.S: The beta version of the TinnRcom package is available to download at:
http://nbcgib.uesc.br/lec/download/R/TinnRcom_1.0-09.zip
-- 
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\
Jose Claudio Faria
Estatistica
UESC/DCET/Brasil
joseclaudio.faria at gmail.com
Telefones:
55(73)3680.5545 - UESC
55(73)9100.7351 - TIM
55(73)8817.6159 - OI
///\\\///\\\///\\\///\\\///\\\///\\\///\\\///\\\



More information about the R-help mailing list