【问题标题】:Error in file(con, "rb") : cannot open the connection External Hard Drive R文件错误(con,“rb”):无法打开连接外部硬盘驱动器 R
【发布时间】:2018-04-29 01:56:34
【问题描述】:

我有以下代码块:

# Obtain records from all patients
patientDir <- sort(list.dirs(path = "sample_images", full.names = TRUE, recursive = FALSE))

dataframes <- list()
i = 1
while(i<19){
  # Strip the patient out
  patient <- coreHist(patientDir[i])

  print("1")
  setwd("/Volumes/HUGE storage drive/")
  exists<- file.exists(patientDir[i])

  print(exists)

  # Extract the relevant information from the patient
  dicom <- readDICOM(patientDir[i])
  dicomdf <- dicomTable(dicom$hdr)  
  patient_id <- dicomdf$`0010-0020-PatientID`[1] 

  print("2")

  # Normalize their VX's
  sum<- sum(patient$histData$finalFreq)

  print("3")

  # Create the new VX's
  patient$histData$finalFreq_scaled <- (patient$histData$finalFreq/sum)

  print("4")

  # Add their ID
  patient$histData$patientid <- patient_id

  print("5")

  # Keep only the important columns
  patient$histData <- patient$histData[c("patientid", "Var1", "finalFreq_scaled")]

  print("6")

  # Add these dataframes to a list for better recall afterwards
  dataframes[[i]] <- patient$histData

  print("7")

  # Additional code to transpose and merge dataframes
  if(i == 1){
    wide_df <- patient$histData
  }else{
    wide_df <- rbind(wide_df,patient$histData )
  }

  print("8")

  print(paste(c("Patient", i), sep ="", collapse = "-"))

  i = i+1
}

但是,在(看似随机的)迭代次数之后,代码在“print("1")”行之后立即失败,并出现以下错误:

Error in file(con, "rb") : cannot open the connection

工作目录设置为外部硬盘驱动器,因为“sample_images”文件夹大小为 62GB。我想可能是与 R studio 和我的外部硬盘驱动器的连接超时,所以我尝试在我的计算机上“保持活动”,我还尝试在每次迭代后重置工作目录以确保它可以找到文件。

当某个患者失败时,我会手动检查该文件是否确实存在,并且确实存在。有什么想法吗?

【问题讨论】:

    标签: r imaging


    【解决方案1】:

    我实际上不确定为什么会发生错误,但为了修复它,我只是添加了一个“try”语句:

      attempt <- 1
      while(is.null(dicom) && attempt <= 3){
        attempt <- attempt + 1
        try(
          dicom <- readDICOM(patientDir[i])
        )  
      }
    

    这确实有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-19
      • 1970-01-01
      相关资源
      最近更新 更多