Пример #1
0
  @Invisible
  @Internal
  public static String setwd(@Current Context context, String workingDirectoryName)
      throws FileSystemException {
    FileObject newWorkingDirectory = context.resolveFile(workingDirectoryName);
    if (!newWorkingDirectory.exists() || newWorkingDirectory.getType() != FileType.FOLDER) {
      throw new EvalException("cannot change working directory");
    }

    String previous = context.getSession().getWorkingDirectory().getName().getURI();

    context.getSession().setWorkingDirectory(newWorkingDirectory);
    return previous;
  }
Пример #2
0
  @Internal("Sys.setenv")
  public static LogicalVector setEnvironment(
      @Current Context context, StringVector names, StringVector values) {

    Map<String, String> map = context.getSession().getSystemEnvironment();

    LogicalArrayVector.Builder result = new LogicalArrayVector.Builder();
    for (int i = 0; i != names.length(); ++i) {
      map.put(names.getElementAsString(i), values.getElementAsString(i));
      result.add(true);
    }
    return result.build();
  }
Пример #3
0
  @Internal("Sys.getenv")
  public static StringVector getEnvironment(
      @Current Context context, StringVector names, String unset) {
    StringVector.Builder result = new StringArrayVector.Builder();

    Map<String, String> map = context.getSession().getSystemEnvironment();
    if (names.length() == 0) {
      for (Map.Entry<String, String> entry : map.entrySet()) {
        result.add(entry.getKey() + "=" + entry.getValue());
      }
    } else {
      for (String name : names) {
        String value = map.get(name);
        result.add(value == null ? unset : value);
      }
    }
    return result.build();
  }
Пример #4
0
  @Internal("system")
  public static SEXP system(
      @Current Context context, String command, int flag, SEXP stdin, SEXP stdout, SEXP stderr)
      throws IOException, InterruptedException {
    boolean invisible = (flag >= 20 && flag < 29);
    boolean minimized = (flag >= 10 && flag < 19);

    List<String> args = parseArgs(command);
    ProcessBuilder builder = new ProcessBuilder(args);

    FileObject workingDir = context.getSession().getWorkingDirectory();
    if (workingDir instanceof LocalFile) {
      File localDir = new File(workingDir.getURL().getFile());
      builder.directory(localDir);
    }
    Process process = builder.start();
    process.waitFor();

    int exitValue = process.exitValue();
    return new IntArrayVector(exitValue);
  }
Пример #5
0
 /**
  * Returns an absolute filename representing the current working directory of the R process;
  * setwd(dir) is used to set the working directory to dir.
  *
  * <p>Renjin maintains its own internal pointer to the working directory which lives in {@link
  * org.renjin.eval.Session}
  *
  * @param context the current call Context
  * @return an absolute filename representing the current working directory
  */
 @Internal
 public static String getwd(@Current Context context) {
   return context.getSession().getWorkingDirectory().getName().getURI();
 }
Пример #6
0
 @Internal
 public static String getRHome(@Current Context context) throws URISyntaxException {
   return context.getSession().getHomeDirectory();
 }
Пример #7
0
 @Internal
 public static StringVector commandArgs(@Current Context context) {
   return context.getSession().getCommandLineArguments();
 }