Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6368601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:41:47+00:00 2026-05-25T00:41:47+00:00

I want to be able to source() a file which includes a different file

  • 0

I want to be able to source() a file which includes a different file in its same directory, but I don’t want to have to set the working directory from the R-prompt before running this file:

> getwd()
[1] "/Users/myser"
> source("/Users/myuser/workspace/myproject/myfile.r")

Inside /Users/myuser/workspace/myproject, there would be myfile.r and my-utils.r. myfile.r calls source('my-utils.r') from within it.

Other programming languages can determine the current file’s path. Does R have something similar? Example:

cur_dir <- sys.get_current_file_path()
source(file.path(cur_dir, "my-utils.r"))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:41:48+00:00Added an answer on May 25, 2026 at 12:41 am
    source("/Users/myuser/workspace/myproject/my-utils.r", chdir=TRUE)
    

    When chdir option is set to true and the source file parameter is a full path, the directory of file will be used as the working directory while sourcing the file.

    NOTE: cur_dir <- sys.get_current_file_path() doesn’t make much sense because pathnames are not unique.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to read from an unsorted source text file (one
Background I want to be able to parse Javascript source in a Delphi Application.
I have an existing jar file which I run. It is the Selenium RC
I have a program which performs a useful task. Now I want to produce
I have a solution file that requires a third party library (open source). The
I have a PHP script which includes one or two other libraries it depends
Word 2007 saves its documents in .docx format which is really a zip file
What I want to do is be able to add a file to my
I have a wxPython application that relies on an external config file. I want
I am using eclipse IDE and want to edit the attached source file of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.