rlads2021 / hw2

HW 2: 試試水溫
0 stars 2 forks source link

執行 homework_output.R 出現 contrib.url 錯誤訊息 #9

Open archielu opened 3 years ago

archielu commented 3 years ago

老師 助教 同學好 我是用git clone 將作業 clone 到 Mac 的本地端。 分別執行 Q1.R 、 Q2.R 沒有問題,但是 Rscript homework_output.R 的時候卻噴出這樣的錯誤訊息:

Error in contrib.url(repos, "source") :
  trying to use CRAN without setting a mirror
Calls: install.packages -> contrib.url
停止執行

感謝 ><

liao961120 commented 3 years ago

你可能需要先打開 R console 手動安裝套件:

install.packages("rmarkdown")

這時應該會跳出要你選擇 CRAN mirror 的選項,可以隨便選一個,之後應該就會下載套件了

patricia40719 commented 3 years ago

我是在執行Rscript homework_output.R時,終端機出現以下資料(前面兩行是我將工作目錄設為本次作業資料夾)

zhongpeijia@Peichia-macbook hw2-patricia40719 % pwd
/Users/zhongpeijia/Documents/GitHub/hw2-patricia40719
zhongpeijia@Peichia-macbook hw2-patricia40719 % Rscript homework_output.R
錯誤: pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available).
停止執行

請問這要怎麼做?謝謝~

liao961120 commented 3 years ago

@patricia40719 你可以幫我在 R Console 裡輸入下方指令:

Sys.getenv("RSTUDIO_PANDOC")

然後把輸出貼上來嗎

archielu commented 3 years ago

你有裝homebrew 嗎 有的話呢以直接

brew install pandoc 
patricia40719 commented 3 years ago

回覆助教的留言,在 R Console 裡輸入Sys.getenv("RSTUDIO_PANDOC")後是這樣

> Sys.getenv("RSTUDIO_PANDOC")
[1] "/Applications/RStudio.app/Contents/MacOS/pandoc"
liao961120 commented 3 years ago

那你可以再試這個指令嗎:

rmarkdown::pandoc_version()
patricia40719 commented 3 years ago

好的,這是Console的結果

> rmarkdown::pandoc_version()
[1] ‘2.11.4’
liao961120 commented 3 years ago

你可以試試看在 Terminal 輸入下方指令:

alias pandoc=/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc

然後再執行一次:

Rscript homework_output.R
patricia40719 commented 3 years ago

在terminal輸入alias pandoc=/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc後,我再執行一次繳交作業的流程,終端機這樣顯示

zhongpeijia@Peichia-macbook ~ % alias pandoc=/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc
zhongpeijia@Peichia-macbook ~ % cd /Users/zhongpeijia/Documents/GitHub/hw2-patricia40719
zhongpeijia@Peichia-macbook hw2-patricia40719 % pwd
/Users/zhongpeijia/Documents/GitHub/hw2-patricia40719
zhongpeijia@Peichia-macbook hw2-patricia40719 % Rscript homework_output.R
錯誤: pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available).
停止執行
liao961120 commented 3 years ago

輸入後是這樣的

zhongpeijia@Peichia-macbook ~ % alias pandoc=/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc
zhongpeijia@Peichia-macbook ~ % Rscript homework_output.R
Fatal error: cannot open file 'homework_output.R': No such file or directory

你要先 cd 到正確的工作目錄喔 (作業資料夾所在的位置)

patricia40719 commented 3 years ago

喔喔對我忘了!我再執行一次繳交作業的流程,終端機這樣顯示

zhongpeijia@Peichia-macbook ~ % alias pandoc=/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc
zhongpeijia@Peichia-macbook ~ % cd /Users/zhongpeijia/Documents/GitHub/hw2-patricia40719
zhongpeijia@Peichia-macbook hw2-patricia40719 % pwd
/Users/zhongpeijia/Documents/GitHub/hw2-patricia40719
zhongpeijia@Peichia-macbook hw2-patricia40719 % Rscript homework_output.R
錯誤: pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available).
停止執行

好像還是跟原本一樣誒TT

liao961120 commented 3 years ago

那你可以試試看在 Terminal 輸入:

export PATH=$PATH:/Applications/RStudio.app/Contents/MacOS

然後再執行一次

Rscript homework_output.R
patricia40719 commented 3 years ago
zhongpeijia@Peichia-macbook ~ % export PATH=$PATH:/Applications/RStudio.app/Contents/MacOS
zhongpeijia@Peichia-macbook ~ % cd /Users/zhongpeijia/Documents/GitHub/hw2-patricia40719
zhongpeijia@Peichia-macbook hw2-patricia40719 % pwd
/Users/zhongpeijia/Documents/GitHub/hw2-patricia40719
zhongpeijia@Peichia-macbook hw2-patricia40719 % Rscript homework_output.R
錯誤: pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available).
停止執行
liao961120 commented 3 years ago

如果還是不行的話,或許要手動安裝 Pandoc,可以直接點擊這裡下載

另外,可以看看目前在 Terminal 裡直接輸入:

pandoc --version

會出現什麼嗎?

patricia40719 commented 3 years ago

輸入pandoc --version後是這樣的

zhongpeijia@Peichia-macbook hw2-patricia40719 % pandoc --version
zsh: permission denied: pandoc

好像還是不行,那我下載看看Pandoc好了!

patricia40719 commented 3 years ago

下載Pandoc後再次執行Rscript homework_output.R,就有東西出來了!

zhongpeijia@Peichia-macbook hw2-patricia40719 % Rscript homework_output.R

processing file: index.Rmd
  |............                                                          |  17%
   inline R code fragments

  |.......................                                               |  33%
label: setup (with options) 
List of 1
 $ include: logi FALSE

  |...................................                                   |  50%
  ordinary text without R code

  |...............................................                       |  67%
label: unnamed-chunk-1 (with options) 
List of 1
 $ code: language xfun::read_utf8("Q1.R")

  |..........................................................            |  83%
  ordinary text without R code

  |......................................................................| 100%
label: unnamed-chunk-2 (with options) 
List of 1
 $ code: language xfun::read_utf8("Q2.R")

output file: index.knit.md

/usr/local/bin/pandoc +RTS -K512m -RTS index.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output index.html --lua-filter /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --variable bs3=TRUE --standalone --section-divs --table-of-contents --toc-depth 3 --variable toc_float=1 --variable toc_selectors=h1,h2,h3 --variable toc_smooth_scroll=1 --variable toc_print=1 --template /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmd/h/default.html --highlight-style tango --number-sections --css style.css --variable theme=bootstrap --include-in-header /var/folders/ht/49sw37hx1fq2_mrx42mk9pkr0000gn/T//RtmpEkV8iS/rmarkdown-str16755247b474.html --mathjax --variable 'mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML' 

Output created: index.html

最後再請問助教一下,這麼一長串東西要怎麼檢查跟自己寫的作業一不一樣呢?

liao961120 commented 3 years ago
Rscript homework_output.R

印出的東西是輸出 R Markdown (之後課程會介紹) 時的 Message,不是作業執行的結果。這邊的目的是產生 index.html (可以用瀏覽器打開) 方便助教批改作業。

如果要看作業的輸出,可以分別檢查 Q1.RQ2.R:

Rscript Q1.R
Rscript Q2.R
patricia40719 commented 3 years ago

好的 謝謝助教

dina496 commented 3 years ago

老師、助教好: 由於我也出現了類似的問題,所以把目前遇到的困難貼在這裡>< 我有按照前面助教的指示操作,下載rmarkdown套件和pandoc,以及在R console和terminal輸入一連串的指令。 接著終端機執行Rscript homework_output.R時出現下面的錯誤訊息

processing file: index.Rmd
Error in parse_block(g[-1], g[1], params.src, markdown_mode) : 
  Duplicate chunk label 'setup', which has been used for the chunk:
a <- seq(from = 101, to = 1, by = -2)
print(a)
print(sum(a))
print(mean(a))
Calls: <Anonymous> ... process_file -> split_file -> lapply -> FUN -> parse_block
停止執行
dinade-MacBook:hw2-dina496 dinalai$ 

請問我是哪裡做錯了呢?(;´༎ຶД༎ຶ`)

seashell14711 commented 3 years ago

助教好: 我照著上面的回覆,下載了rmarkdown的套件和pandoc的套件,之後將工作目錄調整至這次作業的資料夾後執行 Rscript homework_output.R 雖然並沒有跳出任何錯誤訊息,但index.html也沒有出現在這次作業的資料夾 請問應該如何處理呢? 感謝

(pandoc的套件是點擊助教給的連結下載的,不知道下載完之後檔案所在的位置會不會有甚麼影響?)

liao961120 commented 3 years ago

@dina496 你更動到 index.Rmd 這份檔案的 code chunk 囉。這次作業,除了姓名學號的地方,請不要更動 index.Rmd 的內容喔,所有的程式碼請寫在 Q1.R 以及 Q2.R 當中。

解決辦法是去公開的 repo 取得 index.Rmd 17 行之後的所有內容,然後取代掉到你 index.Rmd 中 17 行以後的內容

liao961120 commented 3 years ago

@seashell14711

  1. 想問你的作業系統是?
  2. Pandoc 的下載連結是 Mac 的安裝檔,下載之後應該要執行安裝 (但若你的電腦不是 Mac,就不能使用這個安裝檔)
  3. 你在 Terminal 裡面直接輸入 Rscript 會印出什麼?可以把印出的東西貼上來看看
seashell14711 commented 3 years ago
  1. windows

3 . C:\Users\zxzx5>Rscript Usage: /path/to/Rscript [--options] [-e expr [-e expr2 ...] | file] [args]

--options accepted are --help Print usage and exit --version Print version and exit --verbose Print information on progress --default-packages=list Where 'list' is a comma-separated set of package names, or 'NULL' or options to R, in addition to --no-echo --no-restore, such as --save Do save workspace at the end of the session --no-environ Don't read the site and user environment files --no-site-file Don't read the site-wide Rprofile --no-init-file Don't read the user R profile --restore Do restore previously saved objects at startup --vanilla Combine --no-save, --no-restore, --no-site-file --no-init-file and --no-environ

'file' may contain spaces but not shell metacharacters Expressions (one or more '-e ') may be used instead of 'file' See also ?Rscript from within R

liao961120 commented 3 years ago

@seashell14711 你的問題應該類似 Issue #11 ,之後討論串就在 Issue #11 討論囉

dina496 commented 3 years ago

調整完就可以順利執行了!謝謝助教

AndrewCC0520 commented 3 years ago

助教好 我有像樓上那位同學一樣的問題 但我用的是mac 在terminal裡面輸入Rscript會出現

Usage: /path/to/Rscript [--options] [-e expr [-e expr2 ...] | file] [args]

--options accepted are --help Print usage and exit --version Print version and exit --verbose Print information on progress --default-packages=list Where 'list' is a comma-separated set of package names, or 'NULL' or options to R, in addition to --no-echo --no-restore, such as --save Do save workspace at the end of the session --no-environ Don't read the site and user environment files --no-site-file Don't read the site-wide Rprofile --no-init-file Don't read the user R profile --restore Do restore previously saved objects at startup --vanilla Combine --no-save, --no-restore, --no-site-file --no-init-file and --no-environ

'file' may contain spaces but not shell metacharacters Expressions (one or more '-e ') may be used instead of 'file' See also ?Rscript from within R

再麻煩助教回答了!感謝!

liao961120 commented 3 years ago

@AndrewCC0520 我不太懂你的意思, 可以請你完整描述你的問題嗎?

AndrewCC0520 commented 3 years ago

沒關係我解決了! 謝謝助教的幫忙!

min301 commented 3 years ago

助教您好,我想請問 我一樣是使用mac系統但下載Pandoc後仍無法執行Rscript homework_output.R (Q1.R 和Q2.R 可以) 請問我應如何處理呢~謝謝助教!

linshumin@linshumindeMacBook-Pro ~ % export PATH=$PATH:/Applications/RStudio.app/Contents/MacOS linshumin@linshumindeMacBook-Pro ~ % pwd /Users/linshumin linshumin@linshumindeMacBook-Pro ~ % cd /Users/linshumin/Desktop/學分大作戰/R\ 資料庫/hw2-min301 linshumin@linshumindeMacBook-Pro hw2-min301 % Rscript homework_output.R 錯誤: pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available). 停止執行

liao961120 commented 3 years ago

那你這邊用 RStudio 打開 index.Rmd 然後按 "Knit" 看看能不能輸出:

min301 commented 3 years ago

@liao961120 可以輸出~