You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言here()函数疑问:.here文件定义及创建方法咨询

Hey there! Let's sort out your issue with the here package in R and that confusing .here file.

What Exactly Is the .here File?

The .here file is a simple, empty marker file that tells the here() function where your project's root directory is located. When you call here(), it scans upward from your current working directory until it finds a .here file—once it does, that directory becomes the "root" it uses to build file paths for your project. It doesn't need any content inside; the only thing that matters is its exact name: .here.

How to Create It Correctly

You've got two straightforward options:

  • From R (easiest way)
    Just navigate to your target workflow directory (the one you want to use as your project root) in R, then run this command:

    library(here)
    set_here()
    

    This will automatically create a proper .here file in the right place—no manual file management needed.

  • Manually (outside R)
    If you prefer to create it yourself:

    • On Mac/Linux: Open a terminal, navigate to your project root directory, and run touch .here. This creates an empty file named .here.
    • On Windows: Open Command Prompt, go to your project root, and run type nul > .here. Windows' file explorer can be finicky about creating files without extensions, so using CMD avoids the "you must enter a filename" error.
Why Your .here.txt Didn't Work

The key problem here is the file extension! The here() function only looks for a file with the exact name .here—it ignores any suffix like .txt. Your .here.txt file was invisible to the function, which is why it didn't set your project root correctly.

Quick Verification Step

Once you've created the proper .here file, test it by running:

library(here)
here()

This should print the absolute path to your target workflow directory—if it does, you're all set!

内容的提问来源于stack exchange,提问作者Pierre Dudek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:55:23